Built motion from commit (unavailable).|2.5.4
[motion2.git] / server / services / ami / fax / index.js
index 2e62140..2fa9f0a 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xa7e6=['fax','catch','error','stringify','\x20receiveFax\x20','merge','pick','response','reason','update','AttachmentId','SENDING\x20FAILED\x20','then','logger','[Fax][Message][Error][Updated]','[Fax][Message][Error][NoUpdate1]','[Fax][Message][Error][NoUpdate2]','[Fax][Message][Updated]','[Fax][Message][NoUpdate1]','finally','[Fax][Message][NoUpdate2]','\x20hangup\x20sendFile\x20','SUCCESS','updateStatus','SENDING\x20FAILED:\x20','faxstatusstring','SENDING\x20FAILED','send','FaxAccountId','[Fax][execOriginate][failure]','Fax\x20failed','checkTrunk','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','%s/%s.tif','Convert\x20pdf\x20to\x20tif','Action','variablesAction','execOriginate','addVariables','isTrunkReachable','isNil','active','SIP/%s','reachable','[Fax][checkTrunk][Trunk\x20not\x20work]','\x20Trunk\x20is\x20not\x20active','[Fax][checkTrunk][Empty\x20Fax]','Empty\x20Fax','[Fax][checkTrunk][Empty\x20path]','Empty\x20path','Is\x20Valid','exports','lodash','bluebird','moment','path','../../../config/logger','../ami','./rpcDb','./channel','./util/util','./action','../rpc/faxAccount','../rpc/attachment','../rpc/faxMessage','channels','faxAccounts','trunks','actions','newchannel','varset','syncVarSet','bind','newstate','newexten','faxstatus','hangup','syncHangup','syncOriginateResponse','prototype','syncNewchannel','context','from-voip-provider','exten','uniqueid','channel','name','info','\x20syncNewchannel\x20','variable','hasOwnProperty','value','syncNewState','channelstate','channelstatedesc','syncNewExten','syncFaxStatus','operation','status','localstationid','filename','\x20syncFaxStatus\x20','remotestationid','pagestransferred','transferrate','calleridnum','/var/opt/motion2/server/files/attachments/','\x20result\x20conversion\x20file\x20','message','create','parse','.pdf','application/pdf'];(function(_0x166ec1,_0x5ea555){var _0x5208e6=function(_0x48659a){while(--_0x48659a){_0x166ec1['push'](_0x166ec1['shift']());}};_0x5208e6(++_0x5ea555);}(_0xa7e6,0xab));var _0x6a7e=function(_0x1034ee,_0x12998c){_0x1034ee=_0x1034ee-0x0;var _0x2922af=_0xa7e6[_0x1034ee];return _0x2922af;};'use strict';var util=require('util');var _=require(_0x6a7e('0x0'));var BPromise=require(_0x6a7e('0x1'));var uuid=require('uuid');var moment=require(_0x6a7e('0x2'));var path=require(_0x6a7e('0x3'));var tiff2pdf=require('tiff2pdf');var gs=require('./util/gs');var logger=require(_0x6a7e('0x4'))('fax');var ami=require(_0x6a7e('0x5'));var rpcDb=require(_0x6a7e('0x6'));var Channel=require(_0x6a7e('0x7'));var ut=require(_0x6a7e('0x8'));var Action=require(_0x6a7e('0x9'));var faxAccount=require(_0x6a7e('0xa'));var attachment=require(_0x6a7e('0xb'));var faxMessage=require(_0x6a7e('0xc'));function Fax(_0x21813c){this[_0x6a7e('0xd')]={};this[_0x6a7e('0xe')]=_0x21813c[_0x6a7e('0xe')];this[_0x6a7e('0xf')]=_0x21813c[_0x6a7e('0xf')];this[_0x6a7e('0x10')]={};ami['on'](_0x6a7e('0x11'),this['syncNewchannel']['bind'](this));ami['on'](_0x6a7e('0x12'),this[_0x6a7e('0x13')][_0x6a7e('0x14')](this));ami['on'](_0x6a7e('0x15'),this['syncNewState'][_0x6a7e('0x14')](this));ami['on'](_0x6a7e('0x16'),this['syncNewExten']['bind'](this));ami['on'](_0x6a7e('0x17'),this['syncFaxStatus'][_0x6a7e('0x14')](this));ami['on']('receivefax',this['syncReceiveFax'][_0x6a7e('0x14')](this));ami['on'](_0x6a7e('0x18'),this[_0x6a7e('0x19')][_0x6a7e('0x14')](this));ami['on']('originateresponse',this[_0x6a7e('0x1a')][_0x6a7e('0x14')](this));}Fax[_0x6a7e('0x1b')][_0x6a7e('0x1c')]=function(_0x5e0885){if(_0x5e0885[_0x6a7e('0x1d')]===_0x6a7e('0x1e')){for(var _0x374a12 in this[_0x6a7e('0xe')]){if(this[_0x6a7e('0xe')]['hasOwnProperty'](_0x374a12)){if(_0x5e0885[_0x6a7e('0x1f')]===this[_0x6a7e('0xe')][_0x374a12]['localstationid']){this[_0x6a7e('0xd')][_0x5e0885[_0x6a7e('0x20')]]={};this[_0x6a7e('0xd')][_0x5e0885[_0x6a7e('0x20')]][_0x6a7e('0x21')]=_0x5e0885[_0x6a7e('0x21')];this[_0x6a7e('0xd')][_0x5e0885['uniqueid']]['id']=this[_0x6a7e('0xe')][_0x374a12]['id'];this[_0x6a7e('0xd')][_0x5e0885[_0x6a7e('0x20')]][_0x6a7e('0x22')]=this[_0x6a7e('0xe')][_0x374a12][_0x6a7e('0x22')];logger[_0x6a7e('0x23')](_0x5e0885[_0x6a7e('0x20')],_0x6a7e('0x24'));}}}}if(this[_0x6a7e('0x10')][_0x5e0885[_0x6a7e('0x20')]]){this['channels'][_0x5e0885[_0x6a7e('0x20')]]={};this[_0x6a7e('0xd')][_0x5e0885[_0x6a7e('0x20')]][_0x6a7e('0x21')]=_0x5e0885[_0x6a7e('0x21')];logger[_0x6a7e('0x23')](_0x5e0885[_0x6a7e('0x20')],_0x6a7e('0x24'));}};Fax[_0x6a7e('0x1b')]['syncVarSet']=function(_0x17e34c){if(this['channels'][_0x17e34c['uniqueid']]){for(var _0x584d6b in _0x17e34c[_0x6a7e('0x25')]){if(_0x17e34c['variable'][_0x6a7e('0x26')](_0x584d6b)){this[_0x6a7e('0xd')][_0x17e34c[_0x6a7e('0x20')]][_0x584d6b]=_0x17e34c[_0x6a7e('0x27')];}}}};Fax['prototype'][_0x6a7e('0x28')]=function(_0x5512ec){if(this['channels'][_0x5512ec[_0x6a7e('0x20')]]){this[_0x6a7e('0xd')][_0x5512ec['uniqueid']][_0x6a7e('0x29')]=_0x5512ec[_0x6a7e('0x29')];this[_0x6a7e('0xd')][_0x5512ec['uniqueid']]['channelstatedesc']=_0x5512ec[_0x6a7e('0x2a')];}};Fax['prototype'][_0x6a7e('0x2b')]=function(_0x275c52){if(this['channels'][_0x275c52[_0x6a7e('0x20')]]){for(var _0x4dfee5 in _0x275c52[_0x6a7e('0x25')]){if(_0x275c52[_0x6a7e('0x25')][_0x6a7e('0x26')](_0x4dfee5)){this[_0x6a7e('0xd')][_0x275c52[_0x6a7e('0x20')]][_0x4dfee5]=_0x275c52['value'];}}}};Fax[_0x6a7e('0x1b')][_0x6a7e('0x2c')]=function(_0x370ca8){if(this[_0x6a7e('0xd')][_0x370ca8['uniqueid']]){this[_0x6a7e('0xd')][_0x370ca8[_0x6a7e('0x20')]]['operation']=_0x370ca8[_0x6a7e('0x2d')];this['channels'][_0x370ca8['uniqueid']][_0x6a7e('0x2e')]=_0x370ca8[_0x6a7e('0x2e')];this[_0x6a7e('0xd')][_0x370ca8['uniqueid']][_0x6a7e('0x2f')]=_0x370ca8[_0x6a7e('0x2f')];this[_0x6a7e('0xd')][_0x370ca8[_0x6a7e('0x20')]][_0x6a7e('0x30')]=_0x370ca8[_0x6a7e('0x30')];logger['info'](_0x370ca8[_0x6a7e('0x20')],_0x6a7e('0x31'));}};Fax['prototype']['syncReceiveFax']=function(_0x34b719){var _0x2dcc61=this;if(this[_0x6a7e('0xd')][_0x34b719[_0x6a7e('0x20')]]){var _0x3f0990=this[_0x6a7e('0xd')][_0x34b719['uniqueid']]['id'];this['channels'][_0x34b719[_0x6a7e('0x20')]][_0x6a7e('0x32')]=_0x34b719[_0x6a7e('0x32')];this['channels'][_0x34b719[_0x6a7e('0x20')]][_0x6a7e('0x33')]=_0x34b719[_0x6a7e('0x33')];this[_0x6a7e('0xd')][_0x34b719[_0x6a7e('0x20')]]['localstationid']=_0x34b719[_0x6a7e('0x2f')];this[_0x6a7e('0xd')][_0x34b719[_0x6a7e('0x20')]]['resolution']=_0x34b719['resolution'];this[_0x6a7e('0xd')][_0x34b719[_0x6a7e('0x20')]][_0x6a7e('0x34')]=_0x34b719[_0x6a7e('0x34')];this[_0x6a7e('0xd')][_0x34b719[_0x6a7e('0x20')]][_0x6a7e('0x30')]=_0x34b719[_0x6a7e('0x30')];this[_0x6a7e('0xd')][_0x34b719[_0x6a7e('0x20')]][_0x6a7e('0x35')]=_0x34b719[_0x6a7e('0x35')];if(this[_0x6a7e('0xd')][_0x34b719[_0x6a7e('0x20')]][_0x6a7e('0x33')]>0x0){tiff2pdf(_0x34b719[_0x6a7e('0x30')],_0x6a7e('0x36'),function(_0x536439){logger[_0x6a7e('0x23')](_0x34b719[_0x6a7e('0x20')],_0x6a7e('0x37'),_0x536439[_0x6a7e('0x38')]);attachment[_0x6a7e('0x39')]({'name':path[_0x6a7e('0x3a')](_0x34b719[_0x6a7e('0x30')])['name'],'basename':path[_0x6a7e('0x3a')](_0x34b719[_0x6a7e('0x30')])[_0x6a7e('0x22')]+_0x6a7e('0x3b'),'type':_0x6a7e('0x3c')})['then'](function(_0x43521c){faxAccount['notify'](_0x3f0990,{'from':_0x34b719[_0x6a7e('0x35')],'mapKey':_0x6a7e('0x3d'),'body':path[_0x6a7e('0x3a')](_0x34b719[_0x6a7e('0x30')])[_0x6a7e('0x22')]+_0x6a7e('0x3b'),'AttachmentId':_0x43521c['id']})[_0x6a7e('0x3e')](function(_0x5f550c){logger[_0x6a7e('0x3f')](_0x34b719['uniqueid'],'\x20notify\x20',JSON[_0x6a7e('0x40')](_0x5f550c));});})[_0x6a7e('0x3e')](function(_0x1df7c0){logger[_0x6a7e('0x3f')](_0x34b719[_0x6a7e('0x20')],_0x6a7e('0x41'),JSON[_0x6a7e('0x40')](_0x1df7c0));});});}logger[_0x6a7e('0x23')](_0x34b719['uniqueid'],_0x6a7e('0x41'));}};Fax[_0x6a7e('0x1b')][_0x6a7e('0x1a')]=function(_0xb39fec){if(this['actions'][_0xb39fec[_0x6a7e('0x20')]]){_[_0x6a7e('0x42')](this[_0x6a7e('0xd')][_0xb39fec['uniqueid']],_[_0x6a7e('0x43')](_0xb39fec,[_0x6a7e('0x44'),_0x6a7e('0x45')]));}};function updateStatus(_0x3ed54d){if(_0x3ed54d['AttachmentId']){faxMessage[_0x6a7e('0x46')](_0x3ed54d[_0x6a7e('0x47')],{'failMessage':_0x6a7e('0x48')})[_0x6a7e('0x49')](function(_0x37e41f){ut[_0x6a7e('0x4a')](_0x6a7e('0x4b'),_0x37e41f);})[_0x6a7e('0x3e')](function(_0x53b53e){ut['logger'](_0x6a7e('0x4c'),_0x53b53e);});}else{ut['logger'](_0x6a7e('0x4d'));}}Fax[_0x6a7e('0x1b')]['updateStatus']=function(_0x22f8b8,_0x1d0a94,_0xbea30e){var _0x5652b5=this;var _0x1eed52={};if(_0x1d0a94){_0x1eed52={'read':_0x1d0a94};}else{_0x1eed52={'failMessage':_0xbea30e};}if(this[_0x6a7e('0x10')][_0x22f8b8][_0x6a7e('0x47')]){faxMessage[_0x6a7e('0x46')](this[_0x6a7e('0x10')][_0x22f8b8][_0x6a7e('0x47')],_0x1eed52)[_0x6a7e('0x49')](function(_0xf52efd){ut[_0x6a7e('0x4a')](_0x6a7e('0x4e'),_0xf52efd);})[_0x6a7e('0x3e')](function(_0x4243a5){ut[_0x6a7e('0x4a')](_0x6a7e('0x4f'),_0x4243a5);})[_0x6a7e('0x50')](function(){delete _0x5652b5[_0x6a7e('0xd')][_0x22f8b8];delete _0x5652b5[_0x6a7e('0x10')][_0x22f8b8];});}else{ut[_0x6a7e('0x4a')](_0x6a7e('0x51'));delete this[_0x6a7e('0xd')][_0x22f8b8];delete this[_0x6a7e('0x10')][_0x22f8b8];}};Fax['prototype'][_0x6a7e('0x19')]=function(_0x273c88){var _0x1e37c0=this;if(this[_0x6a7e('0xd')][_0x273c88[_0x6a7e('0x20')]]){if(this['actions'][_0x273c88['uniqueid']]){this[_0x6a7e('0xd')][_0x273c88[_0x6a7e('0x20')]]['id']=this[_0x6a7e('0x10')][_0x273c88['uniqueid']]['id'];this[_0x6a7e('0xd')][_0x273c88[_0x6a7e('0x20')]]['name']=this[_0x6a7e('0x10')][_0x273c88['uniqueid']]['name'];}logger['info'](_0x273c88[_0x6a7e('0x20')],this[_0x6a7e('0x10')][_0x273c88[_0x6a7e('0x20')]]?_0x6a7e('0x52'):'\x20hangup\x20faxRiceive\x20',JSON[_0x6a7e('0x40')](this[_0x6a7e('0xd')][_0x273c88[_0x6a7e('0x20')]]));if(this[_0x6a7e('0x10')][_0x273c88['uniqueid']]){if(this['channels'][_0x273c88['uniqueid']]['faxpages']>0x0&&this[_0x6a7e('0xd')][_0x273c88[_0x6a7e('0x20')]][_0x6a7e('0x17')]===_0x6a7e('0x53')){this['updateStatus'](_0x273c88[_0x6a7e('0x20')],!![]);}else{this[_0x6a7e('0x54')](_0x273c88[_0x6a7e('0x20')],![],this[_0x6a7e('0xd')][_0x273c88['uniqueid']]['faxstatusstring']?_0x6a7e('0x55')+this[_0x6a7e('0xd')][_0x273c88['uniqueid']][_0x6a7e('0x56')]:_0x6a7e('0x57'));}}}};Fax[_0x6a7e('0x1b')][_0x6a7e('0x58')]=function(_0x2aec4d){var _0x585b1a=this;return new BPromise(function(_0x544a14,_0x21c74d){_0x585b1a['execOriginate'](_0x2aec4d,_0x585b1a[_0x6a7e('0xe')][_0x2aec4d[_0x6a7e('0x59')]])[_0x6a7e('0x49')](function(_0x326ea5){ut[_0x6a7e('0x4a')]('[Fax][execOriginate][success]',_0x326ea5);_0x544a14(ut[_0x6a7e('0x38')]('Fax\x20received'));})['catch'](function(_0x502d10){ut[_0x6a7e('0x4a')](_0x6a7e('0x5a'),_0x502d10);updateStatus(_0x2aec4d);_0x21c74d(ut[_0x6a7e('0x38')](_0x6a7e('0x5b')));});});};Fax[_0x6a7e('0x1b')]['checkAfterSend']=function(_0x132f26){var _0x17b533=this;return new BPromise(function(_0x356729,_0x54f9d4){var _0x3803a9=_0x17b533[_0x6a7e('0x5c')](_0x17b533['faxAccounts'][_0x132f26['FaxAccountId']]['Trunk'],_0x132f26);if(_0x3803a9[_0x6a7e('0x5d')]){_0x356729(ut['message'](_0x6a7e('0x5e')));}else{_0x54f9d4(ut['message'](_0x3803a9['message']));}});};function originate(_0x440352,_0xa4ecc3,_0x402f87){return new BPromise(function(_0x4d688c,_0x1123f3){if(_0x402f87){var _0x420cc0=util[_0x6a7e('0x5f')](_0x6a7e('0x60'),path[_0x6a7e('0x3a')](_0x440352['path'])['name'],_0x440352[_0x6a7e('0x3')]);gs['execute'](_0x420cc0)[_0x6a7e('0x49')](function(){_0x440352[_0x6a7e('0x3')]=util[_0x6a7e('0x5f')](_0x6a7e('0x61'),path[_0x6a7e('0x3a')](_0x440352[_0x6a7e('0x3')])['dir'],path[_0x6a7e('0x3a')](_0x440352[_0x6a7e('0x3')])['name']);_0xa4ecc3['XMF-PATH']=_0x440352[_0x6a7e('0x3')];ut[_0x6a7e('0x4a')](_0x6a7e('0x62'),'');ami[_0x6a7e('0x63')](ut[_0x6a7e('0x64')](_0x440352,_0xa4ecc3))[_0x6a7e('0x49')](function(_0x1ba6d5){_0x4d688c(_0x1ba6d5);})[_0x6a7e('0x3e')](function(_0x94ec32){_0x1123f3(_0x94ec32);});})[_0x6a7e('0x3e')](function(_0x4d7a68){_0x1123f3(_0x4d7a68);});}else{ami['Action'](ut[_0x6a7e('0x64')](_0x440352,_0xa4ecc3))['then'](function(_0x5aceb6){_0x4d688c(_0x5aceb6);})['catch'](function(_0x43bb18){_0x1123f3(_0x43bb18);});}});}Fax['prototype'][_0x6a7e('0x65')]=function(_0x5c58a4,_0x59d931){var _0x44bcfe=this;return new BPromise(function(_0x443788,_0x1dd341){var _0x4a1b26=uuid['v4']();var _0x4d4ac3=ut[_0x6a7e('0x66')](_0x5c58a4,_0x59d931);_0x44bcfe['actions'][_0x4a1b26]=new Action(_0x4a1b26,_0x59d931,_0x5c58a4);var _0x431a92=_0x44bcfe['actions'][_0x4a1b26];if(path['parse'](_0x5c58a4[_0x6a7e('0x3')])['ext']===_0x6a7e('0x3b')){originate(_0x431a92,_0x4d4ac3,!![])[_0x6a7e('0x49')](function(_0x5efb9e){_0x443788(_0x5efb9e);})[_0x6a7e('0x3e')](function(_0x4e2c24){_0x1dd341(_0x4e2c24);});}else{originate(_0x431a92,_0x4d4ac3,![])[_0x6a7e('0x49')](function(_0x1d2432){_0x443788(_0x1d2432);})['catch'](function(_0x26d044){_0x1dd341(_0x26d044);});}});};Fax[_0x6a7e('0x1b')][_0x6a7e('0x67')]=function(_0x1048cb){return!_[_0x6a7e('0x68')](_0x1048cb)&&!_[_0x6a7e('0x68')](_0x1048cb[_0x6a7e('0x22')])&&!_[_0x6a7e('0x68')](_0x1048cb[_0x6a7e('0x69')])&&_0x1048cb['active']&&!_['isNil'](this[_0x6a7e('0xf')][util[_0x6a7e('0x5f')]('SIP/%s',_0x1048cb['name'])])&&!_[_0x6a7e('0x68')](this[_0x6a7e('0xf')][util[_0x6a7e('0x5f')](_0x6a7e('0x6a'),_0x1048cb['name'])]['status'])&&(this['trunks'][util[_0x6a7e('0x5f')](_0x6a7e('0x6a'),_0x1048cb['name'])][_0x6a7e('0x2e')]===_0x6a7e('0x6b')||this[_0x6a7e('0xf')][util['format']('SIP/%s',_0x1048cb[_0x6a7e('0x22')])][_0x6a7e('0x2e')]==='unmonitored');};Fax['prototype'][_0x6a7e('0x5c')]=function(_0x3abafe,_0x11f55f){if(!this['isTrunkReachable'](_0x3abafe)){ut[_0x6a7e('0x4a')](_0x6a7e('0x6c'),_['isNil'](_0x3abafe)?'':_0x3abafe[_0x6a7e('0x22')]+_0x6a7e('0x6d'));return{'isValid':![],'message':'Trunk\x20not\x20working'};}if(_[_0x6a7e('0x68')](_0x11f55f['fax'])){ut['logger'](_0x6a7e('0x6e'),JSON['stringify'](_0x11f55f));return{'isValid':![],'message':_0x6a7e('0x6f')};}if(_[_0x6a7e('0x68')](_0x11f55f['path'])){ut[_0x6a7e('0x4a')](_0x6a7e('0x70'),JSON[_0x6a7e('0x40')](_0x11f55f));return{'isValid':![],'message':_0x6a7e('0x71')};}return{'isValid':!![],'message':_0x6a7e('0x72')};};module[_0x6a7e('0x73')]=Fax;
\ No newline at end of file
+var _0x37cf=['send','execOriginate','FaxAccountId','[Fax][execOriginate][failure]','Fax\x20failed','checkAfterSend','checkTrunk','Trunk','isValid','Trunk\x20Reachable','format','%s/%s.tif','dir','XMF-PATH','Convert\x20pdf\x20to\x20tif','Action','variablesAction','addVariables','isTrunkReachable','isNil','active','SIP/%s','reachable','unmonitored','[Fax][checkTrunk][Trunk\x20not\x20work]','\x20Trunk\x20is\x20not\x20active','Trunk\x20not\x20working','[Fax][checkTrunk][Empty\x20Fax]','Empty\x20Fax','[Fax][checkTrunk][Empty\x20path]','Is\x20Valid','exports','util','lodash','uuid','moment','path','tiff2pdf','./util/gs','../../../config/logger','fax','../ami','./channel','./util/util','./action','../rpc/faxMessage','channels','faxAccounts','trunks','actions','newchannel','bind','varset','syncVarSet','newstate','syncNewState','newexten','faxstatus','syncFaxStatus','receivefax','syncReceiveFax','hangup','syncHangup','originateresponse','prototype','context','from-voip-provider','hasOwnProperty','exten','uniqueid','channel','name','info','\x20syncNewchannel\x20','variable','channelstate','channelstatedesc','value','operation','status','localstationid','filename','remotestationid','pagestransferred','resolution','transferrate','calleridnum','/var/opt/motion2/server/files/attachments/','\x20result\x20conversion\x20file\x20','message','parse','.pdf','then','catch','stringify','\x20receiveFax\x20','syncOriginateResponse','merge','pick','reason','AttachmentId','update','SENDING\x20FAILED\x20','logger','[Fax][Message][Error][Updated]','[Fax][Message][Error][NoUpdate1]','[Fax][Message][Error][NoUpdate2]','[Fax][Message][Updated]','[Fax][Message][NoUpdate1]','finally','[Fax][Message][NoUpdate2]','\x20hangup\x20sendFile\x20','\x20hangup\x20faxRiceive\x20','SUCCESS','updateStatus','faxstatusstring'];(function(_0x169f51,_0x1d4cd1){var _0x1cfe54=function(_0x55e1cb){while(--_0x55e1cb){_0x169f51['push'](_0x169f51['shift']());}};_0x1cfe54(++_0x1d4cd1);}(_0x37cf,0x1f0));var _0xf37c=function(_0x192eee,_0x5c6d10){_0x192eee=_0x192eee-0x0;var _0xacfcd2=_0x37cf[_0x192eee];return _0xacfcd2;};'use strict';var util=require(_0xf37c('0x0'));var _=require(_0xf37c('0x1'));var BPromise=require('bluebird');var uuid=require(_0xf37c('0x2'));var moment=require(_0xf37c('0x3'));var path=require(_0xf37c('0x4'));var tiff2pdf=require(_0xf37c('0x5'));var gs=require(_0xf37c('0x6'));var logger=require(_0xf37c('0x7'))(_0xf37c('0x8'));var ami=require(_0xf37c('0x9'));var rpcDb=require('./rpcDb');var Channel=require(_0xf37c('0xa'));var ut=require(_0xf37c('0xb'));var Action=require(_0xf37c('0xc'));var faxAccount=require('../rpc/faxAccount');var attachment=require('../rpc/attachment');var faxMessage=require(_0xf37c('0xd'));function Fax(_0x351796){this[_0xf37c('0xe')]={};this['faxAccounts']=_0x351796[_0xf37c('0xf')];this[_0xf37c('0x10')]=_0x351796['trunks'];this[_0xf37c('0x11')]={};ami['on'](_0xf37c('0x12'),this['syncNewchannel'][_0xf37c('0x13')](this));ami['on'](_0xf37c('0x14'),this[_0xf37c('0x15')][_0xf37c('0x13')](this));ami['on'](_0xf37c('0x16'),this[_0xf37c('0x17')][_0xf37c('0x13')](this));ami['on'](_0xf37c('0x18'),this['syncNewExten'][_0xf37c('0x13')](this));ami['on'](_0xf37c('0x19'),this[_0xf37c('0x1a')][_0xf37c('0x13')](this));ami['on'](_0xf37c('0x1b'),this[_0xf37c('0x1c')][_0xf37c('0x13')](this));ami['on'](_0xf37c('0x1d'),this[_0xf37c('0x1e')]['bind'](this));ami['on'](_0xf37c('0x1f'),this['syncOriginateResponse'][_0xf37c('0x13')](this));}Fax[_0xf37c('0x20')]['syncNewchannel']=function(_0x1f7591){if(_0x1f7591[_0xf37c('0x21')]===_0xf37c('0x22')){for(var _0x1b4b45 in this[_0xf37c('0xf')]){if(this[_0xf37c('0xf')][_0xf37c('0x23')](_0x1b4b45)){if(_0x1f7591[_0xf37c('0x24')]===this[_0xf37c('0xf')][_0x1b4b45]['localstationid']){this[_0xf37c('0xe')][_0x1f7591[_0xf37c('0x25')]]={};this['channels'][_0x1f7591[_0xf37c('0x25')]][_0xf37c('0x26')]=_0x1f7591[_0xf37c('0x26')];this[_0xf37c('0xe')][_0x1f7591[_0xf37c('0x25')]]['id']=this[_0xf37c('0xf')][_0x1b4b45]['id'];this['channels'][_0x1f7591[_0xf37c('0x25')]][_0xf37c('0x27')]=this[_0xf37c('0xf')][_0x1b4b45][_0xf37c('0x27')];logger[_0xf37c('0x28')](_0x1f7591['uniqueid'],_0xf37c('0x29'));}}}}if(this['actions'][_0x1f7591[_0xf37c('0x25')]]){this[_0xf37c('0xe')][_0x1f7591[_0xf37c('0x25')]]={};this['channels'][_0x1f7591[_0xf37c('0x25')]][_0xf37c('0x26')]=_0x1f7591['channel'];logger[_0xf37c('0x28')](_0x1f7591['uniqueid'],_0xf37c('0x29'));}};Fax['prototype'][_0xf37c('0x15')]=function(_0x4b1a18){if(this[_0xf37c('0xe')][_0x4b1a18[_0xf37c('0x25')]]){for(var _0x3d1a72 in _0x4b1a18[_0xf37c('0x2a')]){if(_0x4b1a18['variable'][_0xf37c('0x23')](_0x3d1a72)){this[_0xf37c('0xe')][_0x4b1a18[_0xf37c('0x25')]][_0x3d1a72]=_0x4b1a18['value'];}}}};Fax[_0xf37c('0x20')][_0xf37c('0x17')]=function(_0x2ab974){if(this[_0xf37c('0xe')][_0x2ab974[_0xf37c('0x25')]]){this[_0xf37c('0xe')][_0x2ab974[_0xf37c('0x25')]][_0xf37c('0x2b')]=_0x2ab974[_0xf37c('0x2b')];this[_0xf37c('0xe')][_0x2ab974[_0xf37c('0x25')]][_0xf37c('0x2c')]=_0x2ab974[_0xf37c('0x2c')];}};Fax[_0xf37c('0x20')]['syncNewExten']=function(_0xdf45f){if(this[_0xf37c('0xe')][_0xdf45f['uniqueid']]){for(var _0xf32f6d in _0xdf45f[_0xf37c('0x2a')]){if(_0xdf45f['variable'][_0xf37c('0x23')](_0xf32f6d)){this[_0xf37c('0xe')][_0xdf45f[_0xf37c('0x25')]][_0xf32f6d]=_0xdf45f[_0xf37c('0x2d')];}}}};Fax[_0xf37c('0x20')]['syncFaxStatus']=function(_0x411af3){if(this[_0xf37c('0xe')][_0x411af3[_0xf37c('0x25')]]){this[_0xf37c('0xe')][_0x411af3[_0xf37c('0x25')]][_0xf37c('0x2e')]=_0x411af3['operation'];this[_0xf37c('0xe')][_0x411af3[_0xf37c('0x25')]]['status']=_0x411af3[_0xf37c('0x2f')];this['channels'][_0x411af3[_0xf37c('0x25')]][_0xf37c('0x30')]=_0x411af3['localstationid'];this[_0xf37c('0xe')][_0x411af3[_0xf37c('0x25')]][_0xf37c('0x31')]=_0x411af3[_0xf37c('0x31')];logger[_0xf37c('0x28')](_0x411af3['uniqueid'],'\x20syncFaxStatus\x20');}};Fax[_0xf37c('0x20')]['syncReceiveFax']=function(_0x199e4e){var _0x27cb2b=this;if(this[_0xf37c('0xe')][_0x199e4e[_0xf37c('0x25')]]){var _0x4b848b=this['channels'][_0x199e4e['uniqueid']]['id'];this[_0xf37c('0xe')][_0x199e4e[_0xf37c('0x25')]][_0xf37c('0x32')]=_0x199e4e[_0xf37c('0x32')];this['channels'][_0x199e4e[_0xf37c('0x25')]][_0xf37c('0x33')]=_0x199e4e['pagestransferred'];this[_0xf37c('0xe')][_0x199e4e['uniqueid']]['localstationid']=_0x199e4e[_0xf37c('0x30')];this['channels'][_0x199e4e[_0xf37c('0x25')]]['resolution']=_0x199e4e[_0xf37c('0x34')];this[_0xf37c('0xe')][_0x199e4e[_0xf37c('0x25')]][_0xf37c('0x35')]=_0x199e4e[_0xf37c('0x35')];this[_0xf37c('0xe')][_0x199e4e[_0xf37c('0x25')]]['filename']=_0x199e4e[_0xf37c('0x31')];this['channels'][_0x199e4e[_0xf37c('0x25')]][_0xf37c('0x36')]=_0x199e4e[_0xf37c('0x36')];if(this[_0xf37c('0xe')][_0x199e4e[_0xf37c('0x25')]]['pagestransferred']>0x0){tiff2pdf(_0x199e4e['filename'],_0xf37c('0x37'),function(_0x3f99e6){logger[_0xf37c('0x28')](_0x199e4e['uniqueid'],_0xf37c('0x38'),_0x3f99e6[_0xf37c('0x39')]);attachment['create']({'name':path[_0xf37c('0x3a')](_0x199e4e[_0xf37c('0x31')])[_0xf37c('0x27')],'basename':path['parse'](_0x199e4e[_0xf37c('0x31')])[_0xf37c('0x27')]+_0xf37c('0x3b'),'type':'application/pdf'})[_0xf37c('0x3c')](function(_0x53806f){faxAccount['notify'](_0x4b848b,{'from':_0x199e4e[_0xf37c('0x36')],'mapKey':_0xf37c('0x8'),'body':path[_0xf37c('0x3a')](_0x199e4e[_0xf37c('0x31')])[_0xf37c('0x27')]+_0xf37c('0x3b'),'AttachmentId':_0x53806f['id']})[_0xf37c('0x3d')](function(_0x331562){logger['error'](_0x199e4e[_0xf37c('0x25')],'\x20notify\x20',JSON[_0xf37c('0x3e')](_0x331562));});})[_0xf37c('0x3d')](function(_0x40aeda){logger['error'](_0x199e4e[_0xf37c('0x25')],_0xf37c('0x3f'),JSON[_0xf37c('0x3e')](_0x40aeda));});});}logger['info'](_0x199e4e[_0xf37c('0x25')],_0xf37c('0x3f'));}};Fax['prototype'][_0xf37c('0x40')]=function(_0xf65943){if(this[_0xf37c('0x11')][_0xf65943[_0xf37c('0x25')]]){_[_0xf37c('0x41')](this[_0xf37c('0xe')][_0xf65943['uniqueid']],_[_0xf37c('0x42')](_0xf65943,['response',_0xf37c('0x43')]));}};function updateStatus(_0x42e668){if(_0x42e668[_0xf37c('0x44')]){faxMessage[_0xf37c('0x45')](_0x42e668[_0xf37c('0x44')],{'failMessage':_0xf37c('0x46')})['then'](function(_0x3bc079){ut[_0xf37c('0x47')](_0xf37c('0x48'),_0x3bc079);})['catch'](function(_0x30ddb3){ut['logger'](_0xf37c('0x49'),_0x30ddb3);});}else{ut[_0xf37c('0x47')](_0xf37c('0x4a'));}}Fax[_0xf37c('0x20')]['updateStatus']=function(_0x5b9b9f,_0x57e5ad,_0x575a4c){var _0x4ef10d=this;var _0x184d84={};if(_0x57e5ad){_0x184d84={'read':_0x57e5ad};}else{_0x184d84={'failMessage':_0x575a4c};}if(this[_0xf37c('0x11')][_0x5b9b9f][_0xf37c('0x44')]){faxMessage['update'](this[_0xf37c('0x11')][_0x5b9b9f]['AttachmentId'],_0x184d84)['then'](function(_0xf2e6dd){ut[_0xf37c('0x47')](_0xf37c('0x4b'),_0xf2e6dd);})[_0xf37c('0x3d')](function(_0x1a27db){ut[_0xf37c('0x47')](_0xf37c('0x4c'),_0x1a27db);})[_0xf37c('0x4d')](function(){delete _0x4ef10d['channels'][_0x5b9b9f];delete _0x4ef10d[_0xf37c('0x11')][_0x5b9b9f];});}else{ut[_0xf37c('0x47')](_0xf37c('0x4e'));delete this[_0xf37c('0xe')][_0x5b9b9f];delete this['actions'][_0x5b9b9f];}};Fax[_0xf37c('0x20')][_0xf37c('0x1e')]=function(_0x387839){var _0xea371f=this;if(this[_0xf37c('0xe')][_0x387839[_0xf37c('0x25')]]){if(this[_0xf37c('0x11')][_0x387839[_0xf37c('0x25')]]){this[_0xf37c('0xe')][_0x387839[_0xf37c('0x25')]]['id']=this[_0xf37c('0x11')][_0x387839['uniqueid']]['id'];this[_0xf37c('0xe')][_0x387839[_0xf37c('0x25')]][_0xf37c('0x27')]=this[_0xf37c('0x11')][_0x387839[_0xf37c('0x25')]]['name'];}logger[_0xf37c('0x28')](_0x387839[_0xf37c('0x25')],this[_0xf37c('0x11')][_0x387839['uniqueid']]?_0xf37c('0x4f'):_0xf37c('0x50'),JSON[_0xf37c('0x3e')](this['channels'][_0x387839['uniqueid']]));if(this[_0xf37c('0x11')][_0x387839['uniqueid']]){if(this['channels'][_0x387839['uniqueid']]['faxpages']>0x0&&this[_0xf37c('0xe')][_0x387839['uniqueid']][_0xf37c('0x19')]===_0xf37c('0x51')){this['updateStatus'](_0x387839[_0xf37c('0x25')],!![]);}else{this[_0xf37c('0x52')](_0x387839[_0xf37c('0x25')],![],this[_0xf37c('0xe')][_0x387839['uniqueid']]['faxstatusstring']?'SENDING\x20FAILED:\x20'+this[_0xf37c('0xe')][_0x387839[_0xf37c('0x25')]][_0xf37c('0x53')]:'SENDING\x20FAILED');}}}};Fax[_0xf37c('0x20')][_0xf37c('0x54')]=function(_0x1258f9){var _0x104eaa=this;return new BPromise(function(_0x259f0c,_0xcca2e1){_0x104eaa[_0xf37c('0x55')](_0x1258f9,_0x104eaa['faxAccounts'][_0x1258f9[_0xf37c('0x56')]])[_0xf37c('0x3c')](function(_0x38aa21){ut[_0xf37c('0x47')]('[Fax][execOriginate][success]',_0x38aa21);_0x259f0c(ut[_0xf37c('0x39')]('Fax\x20received'));})[_0xf37c('0x3d')](function(_0x1f4f00){ut[_0xf37c('0x47')](_0xf37c('0x57'),_0x1f4f00);updateStatus(_0x1258f9);_0xcca2e1(ut[_0xf37c('0x39')](_0xf37c('0x58')));});});};Fax[_0xf37c('0x20')][_0xf37c('0x59')]=function(_0x5b36e0){var _0x43088c=this;return new BPromise(function(_0x1b8c9c,_0x2c2cfb){var _0x4dd372=_0x43088c[_0xf37c('0x5a')](_0x43088c[_0xf37c('0xf')][_0x5b36e0[_0xf37c('0x56')]][_0xf37c('0x5b')],_0x5b36e0);if(_0x4dd372[_0xf37c('0x5c')]){_0x1b8c9c(ut[_0xf37c('0x39')](_0xf37c('0x5d')));}else{_0x2c2cfb(ut[_0xf37c('0x39')](_0x4dd372[_0xf37c('0x39')]));}});};function originate(_0x1c2062,_0x32f504,_0x902973){return new BPromise(function(_0x508966,_0x5c9760){if(_0x902973){var _0x46c442=util[_0xf37c('0x5e')]('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[_0xf37c('0x3a')](_0x1c2062[_0xf37c('0x4')])[_0xf37c('0x27')],_0x1c2062[_0xf37c('0x4')]);gs['execute'](_0x46c442)['then'](function(){_0x1c2062[_0xf37c('0x4')]=util[_0xf37c('0x5e')](_0xf37c('0x5f'),path[_0xf37c('0x3a')](_0x1c2062[_0xf37c('0x4')])[_0xf37c('0x60')],path['parse'](_0x1c2062[_0xf37c('0x4')])['name']);_0x32f504[_0xf37c('0x61')]=_0x1c2062['path'];ut[_0xf37c('0x47')](_0xf37c('0x62'),'');ami[_0xf37c('0x63')](ut[_0xf37c('0x64')](_0x1c2062,_0x32f504))[_0xf37c('0x3c')](function(_0x36b7de){_0x508966(_0x36b7de);})['catch'](function(_0x317f3a){_0x5c9760(_0x317f3a);});})['catch'](function(_0x347b3c){_0x5c9760(_0x347b3c);});}else{ami[_0xf37c('0x63')](ut[_0xf37c('0x64')](_0x1c2062,_0x32f504))[_0xf37c('0x3c')](function(_0x4d91ef){_0x508966(_0x4d91ef);})['catch'](function(_0x39576a){_0x5c9760(_0x39576a);});}});}Fax[_0xf37c('0x20')][_0xf37c('0x55')]=function(_0x14f4a2,_0x37c3de){var _0x1d57ad=this;return new BPromise(function(_0x1e9f95,_0xc9a2a2){var _0x3e4114=uuid['v4']();var _0x2a6802=ut[_0xf37c('0x65')](_0x14f4a2,_0x37c3de);_0x1d57ad['actions'][_0x3e4114]=new Action(_0x3e4114,_0x37c3de,_0x14f4a2);var _0x2fa39b=_0x1d57ad[_0xf37c('0x11')][_0x3e4114];if(path[_0xf37c('0x3a')](_0x14f4a2[_0xf37c('0x4')])['ext']===_0xf37c('0x3b')){originate(_0x2fa39b,_0x2a6802,!![])[_0xf37c('0x3c')](function(_0x460fe2){_0x1e9f95(_0x460fe2);})[_0xf37c('0x3d')](function(_0x5cdf9e){_0xc9a2a2(_0x5cdf9e);});}else{originate(_0x2fa39b,_0x2a6802,![])[_0xf37c('0x3c')](function(_0x4dcdc9){_0x1e9f95(_0x4dcdc9);})[_0xf37c('0x3d')](function(_0x14829c){_0xc9a2a2(_0x14829c);});}});};Fax[_0xf37c('0x20')][_0xf37c('0x66')]=function(_0x5dd08e){return!_[_0xf37c('0x67')](_0x5dd08e)&&!_['isNil'](_0x5dd08e['name'])&&!_[_0xf37c('0x67')](_0x5dd08e['active'])&&_0x5dd08e[_0xf37c('0x68')]&&!_[_0xf37c('0x67')](this[_0xf37c('0x10')][util[_0xf37c('0x5e')](_0xf37c('0x69'),_0x5dd08e[_0xf37c('0x27')])])&&!_[_0xf37c('0x67')](this[_0xf37c('0x10')][util[_0xf37c('0x5e')](_0xf37c('0x69'),_0x5dd08e[_0xf37c('0x27')])][_0xf37c('0x2f')])&&(this[_0xf37c('0x10')][util[_0xf37c('0x5e')](_0xf37c('0x69'),_0x5dd08e[_0xf37c('0x27')])][_0xf37c('0x2f')]===_0xf37c('0x6a')||this[_0xf37c('0x10')][util['format']('SIP/%s',_0x5dd08e['name'])][_0xf37c('0x2f')]===_0xf37c('0x6b'));};Fax['prototype'][_0xf37c('0x5a')]=function(_0x3204cb,_0x4c0935){if(!this[_0xf37c('0x66')](_0x3204cb)){ut['logger'](_0xf37c('0x6c'),_[_0xf37c('0x67')](_0x3204cb)?'':_0x3204cb[_0xf37c('0x27')]+_0xf37c('0x6d'));return{'isValid':![],'message':_0xf37c('0x6e')};}if(_['isNil'](_0x4c0935[_0xf37c('0x8')])){ut[_0xf37c('0x47')](_0xf37c('0x6f'),JSON['stringify'](_0x4c0935));return{'isValid':![],'message':_0xf37c('0x70')};}if(_[_0xf37c('0x67')](_0x4c0935[_0xf37c('0x4')])){ut[_0xf37c('0x47')](_0xf37c('0x71'),JSON['stringify'](_0x4c0935));return{'isValid':![],'message':'Empty\x20path'};}return{'isValid':!![],'message':_0xf37c('0x72')};};module[_0xf37c('0x73')]=Fax;
\ No newline at end of file