Built motion from commit (unavailable).|2.5.31
[motion2.git] / server / services / ami / fax / index.js
index 9fef474..c031b61 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xeb42=['XMF-PATH','Action','variablesAction','addVariables','ext','isTrunkReachable','isNil','active','SIP/%s','status','reachable','unmonitored','\x20Trunk\x20is\x20not\x20active','Empty\x20Fax','Empty\x20path','exports','util','bluebird','moment','./util/gs','../../../config/logger','fax','../ami','./rpcDb','./channel','./util/util','./action','../rpc/faxAccount','../rpc/attachment','../rpc/faxMessage','channels','faxAccounts','trunks','actions','newchannel','syncNewchannel','bind','varset','syncNewState','newexten','syncNewExten','syncFaxStatus','receivefax','syncReceiveFax','syncHangup','originateresponse','syncOriginateResponse','hasOwnProperty','uniqueid','channel','name','info','\x20syncNewchannel\x20','prototype','syncVarSet','variable','value','channelstatedesc','operation','localstationid','filename','remotestationid','pagestransferred','resolution','transferrate','calleridnum','/var/opt/motion2/server/files/attachments/','\x20result\x20conversion\x20file\x20','message','create','parse','.pdf','then','catch','error','stringify','\x20receiveFax\x20','merge','pick','response','AttachmentId','update','logger','[Fax][Message][Error][NoUpdate1]','[Fax][Message][Error][NoUpdate2]','updateStatus','[Fax][Message][Updated]','finally','[Fax][Message][NoUpdate2]','\x20hangup\x20sendFile\x20','faxstatus','SUCCESS','faxstatusstring','SENDING\x20FAILED:\x20','send','execOriginate','FaxAccountId','[Fax][execOriginate][failure]','Fax\x20failed','checkAfterSend','checkTrunk','Trunk','isValid','Trunk\x20Reachable','format','path','%s/%s.tif'];(function(_0x344a3f,_0x579a22){var _0x264712=function(_0x34c9f0){while(--_0x34c9f0){_0x344a3f['push'](_0x344a3f['shift']());}};_0x264712(++_0x579a22);}(_0xeb42,0x1bc));var _0x2eb4=function(_0x2f3794,_0x3c3bec){_0x2f3794=_0x2f3794-0x0;var _0x1c9fbe=_0xeb42[_0x2f3794];return _0x1c9fbe;};'use strict';var util=require(_0x2eb4('0x0'));var _=require('lodash');var BPromise=require(_0x2eb4('0x1'));var uuid=require('uuid');var moment=require(_0x2eb4('0x2'));var path=require('path');var tiff2pdf=require('tiff2pdf');var gs=require(_0x2eb4('0x3'));var logger=require(_0x2eb4('0x4'))(_0x2eb4('0x5'));var ami=require(_0x2eb4('0x6'));var rpcDb=require(_0x2eb4('0x7'));var Channel=require(_0x2eb4('0x8'));var ut=require(_0x2eb4('0x9'));var Action=require(_0x2eb4('0xa'));var faxAccount=require(_0x2eb4('0xb'));var attachment=require(_0x2eb4('0xc'));var faxMessage=require(_0x2eb4('0xd'));function Fax(_0x28f413){this[_0x2eb4('0xe')]={};this[_0x2eb4('0xf')]=_0x28f413[_0x2eb4('0xf')];this[_0x2eb4('0x10')]=_0x28f413[_0x2eb4('0x10')];this[_0x2eb4('0x11')]={};ami['on'](_0x2eb4('0x12'),this[_0x2eb4('0x13')][_0x2eb4('0x14')](this));ami['on'](_0x2eb4('0x15'),this['syncVarSet'][_0x2eb4('0x14')](this));ami['on']('newstate',this[_0x2eb4('0x16')][_0x2eb4('0x14')](this));ami['on'](_0x2eb4('0x17'),this[_0x2eb4('0x18')][_0x2eb4('0x14')](this));ami['on']('faxstatus',this[_0x2eb4('0x19')][_0x2eb4('0x14')](this));ami['on'](_0x2eb4('0x1a'),this[_0x2eb4('0x1b')]['bind'](this));ami['on']('hangup',this[_0x2eb4('0x1c')][_0x2eb4('0x14')](this));ami['on'](_0x2eb4('0x1d'),this[_0x2eb4('0x1e')][_0x2eb4('0x14')](this));}Fax['prototype'][_0x2eb4('0x13')]=function(_0x46e676){if(_0x46e676['context']==='from-voip-provider'){for(var _0x52b45c in this[_0x2eb4('0xf')]){if(this['faxAccounts'][_0x2eb4('0x1f')](_0x52b45c)){if(_0x46e676['exten']===this[_0x2eb4('0xf')][_0x52b45c]['localstationid']){this[_0x2eb4('0xe')][_0x46e676['uniqueid']]={};this[_0x2eb4('0xe')][_0x46e676[_0x2eb4('0x20')]]['channel']=_0x46e676[_0x2eb4('0x21')];this[_0x2eb4('0xe')][_0x46e676[_0x2eb4('0x20')]]['id']=this['faxAccounts'][_0x52b45c]['id'];this['channels'][_0x46e676[_0x2eb4('0x20')]][_0x2eb4('0x22')]=this[_0x2eb4('0xf')][_0x52b45c]['name'];logger[_0x2eb4('0x23')](_0x46e676['uniqueid'],_0x2eb4('0x24'));}}}}if(this[_0x2eb4('0x11')][_0x46e676[_0x2eb4('0x20')]]){this['channels'][_0x46e676[_0x2eb4('0x20')]]={};this[_0x2eb4('0xe')][_0x46e676[_0x2eb4('0x20')]]['channel']=_0x46e676[_0x2eb4('0x21')];logger[_0x2eb4('0x23')](_0x46e676[_0x2eb4('0x20')],_0x2eb4('0x24'));}};Fax[_0x2eb4('0x25')][_0x2eb4('0x26')]=function(_0xde3205){if(this[_0x2eb4('0xe')][_0xde3205[_0x2eb4('0x20')]]){for(var _0x32ce31 in _0xde3205['variable']){if(_0xde3205[_0x2eb4('0x27')][_0x2eb4('0x1f')](_0x32ce31)){this[_0x2eb4('0xe')][_0xde3205[_0x2eb4('0x20')]][_0x32ce31]=_0xde3205[_0x2eb4('0x28')];}}}};Fax[_0x2eb4('0x25')][_0x2eb4('0x16')]=function(_0x4e627a){if(this[_0x2eb4('0xe')][_0x4e627a[_0x2eb4('0x20')]]){this['channels'][_0x4e627a[_0x2eb4('0x20')]]['channelstate']=_0x4e627a['channelstate'];this[_0x2eb4('0xe')][_0x4e627a['uniqueid']]['channelstatedesc']=_0x4e627a[_0x2eb4('0x29')];}};Fax['prototype'][_0x2eb4('0x18')]=function(_0x31c5d3){if(this[_0x2eb4('0xe')][_0x31c5d3[_0x2eb4('0x20')]]){for(var _0x559135 in _0x31c5d3[_0x2eb4('0x27')]){if(_0x31c5d3[_0x2eb4('0x27')][_0x2eb4('0x1f')](_0x559135)){this[_0x2eb4('0xe')][_0x31c5d3[_0x2eb4('0x20')]][_0x559135]=_0x31c5d3[_0x2eb4('0x28')];}}}};Fax['prototype']['syncFaxStatus']=function(_0x3c92f9){if(this['channels'][_0x3c92f9['uniqueid']]){this[_0x2eb4('0xe')][_0x3c92f9[_0x2eb4('0x20')]]['operation']=_0x3c92f9[_0x2eb4('0x2a')];this['channels'][_0x3c92f9[_0x2eb4('0x20')]]['status']=_0x3c92f9['status'];this['channels'][_0x3c92f9['uniqueid']]['localstationid']=_0x3c92f9[_0x2eb4('0x2b')];this[_0x2eb4('0xe')][_0x3c92f9[_0x2eb4('0x20')]]['filename']=_0x3c92f9[_0x2eb4('0x2c')];logger['info'](_0x3c92f9[_0x2eb4('0x20')],'\x20syncFaxStatus\x20');}};Fax[_0x2eb4('0x25')]['syncReceiveFax']=function(_0x3eca7f){var _0x264490=this;if(this[_0x2eb4('0xe')][_0x3eca7f[_0x2eb4('0x20')]]){var _0x7cb0dc=this[_0x2eb4('0xe')][_0x3eca7f[_0x2eb4('0x20')]]['id'];this[_0x2eb4('0xe')][_0x3eca7f[_0x2eb4('0x20')]][_0x2eb4('0x2d')]=_0x3eca7f[_0x2eb4('0x2d')];this[_0x2eb4('0xe')][_0x3eca7f[_0x2eb4('0x20')]][_0x2eb4('0x2e')]=_0x3eca7f[_0x2eb4('0x2e')];this['channels'][_0x3eca7f['uniqueid']][_0x2eb4('0x2b')]=_0x3eca7f[_0x2eb4('0x2b')];this[_0x2eb4('0xe')][_0x3eca7f['uniqueid']][_0x2eb4('0x2f')]=_0x3eca7f[_0x2eb4('0x2f')];this[_0x2eb4('0xe')][_0x3eca7f[_0x2eb4('0x20')]][_0x2eb4('0x30')]=_0x3eca7f[_0x2eb4('0x30')];this['channels'][_0x3eca7f['uniqueid']]['filename']=_0x3eca7f[_0x2eb4('0x2c')];this[_0x2eb4('0xe')][_0x3eca7f[_0x2eb4('0x20')]][_0x2eb4('0x31')]=_0x3eca7f['calleridnum'];if(this[_0x2eb4('0xe')][_0x3eca7f[_0x2eb4('0x20')]][_0x2eb4('0x2e')]>0x0){tiff2pdf(_0x3eca7f[_0x2eb4('0x2c')],_0x2eb4('0x32'),function(_0x30af79){logger[_0x2eb4('0x23')](_0x3eca7f[_0x2eb4('0x20')],_0x2eb4('0x33'),_0x30af79[_0x2eb4('0x34')]);attachment[_0x2eb4('0x35')]({'name':path[_0x2eb4('0x36')](_0x3eca7f[_0x2eb4('0x2c')])[_0x2eb4('0x22')],'basename':path[_0x2eb4('0x36')](_0x3eca7f[_0x2eb4('0x2c')])['name']+_0x2eb4('0x37'),'type':'application/pdf'})[_0x2eb4('0x38')](function(_0x280364){faxAccount['notify'](_0x7cb0dc,{'from':_0x3eca7f[_0x2eb4('0x31')],'mapKey':_0x2eb4('0x5'),'body':path[_0x2eb4('0x36')](_0x3eca7f['filename'])['name']+_0x2eb4('0x37'),'AttachmentId':_0x280364['id']})[_0x2eb4('0x39')](function(_0x20c07a){logger[_0x2eb4('0x3a')](_0x3eca7f[_0x2eb4('0x20')],'\x20notify\x20',JSON[_0x2eb4('0x3b')](_0x20c07a));});})[_0x2eb4('0x39')](function(_0x437d2c){logger[_0x2eb4('0x3a')](_0x3eca7f[_0x2eb4('0x20')],'\x20receiveFax\x20',JSON[_0x2eb4('0x3b')](_0x437d2c));});});}logger[_0x2eb4('0x23')](_0x3eca7f[_0x2eb4('0x20')],_0x2eb4('0x3c'));}};Fax[_0x2eb4('0x25')][_0x2eb4('0x1e')]=function(_0x27ed9){if(this[_0x2eb4('0x11')][_0x27ed9[_0x2eb4('0x20')]]){_[_0x2eb4('0x3d')](this['channels'][_0x27ed9[_0x2eb4('0x20')]],_[_0x2eb4('0x3e')](_0x27ed9,[_0x2eb4('0x3f'),'reason']));}};function updateStatus(_0x3bcac7){if(_0x3bcac7[_0x2eb4('0x40')]){faxMessage[_0x2eb4('0x41')](_0x3bcac7[_0x2eb4('0x40')],{'failMessage':'SENDING\x20FAILED\x20'})[_0x2eb4('0x38')](function(_0x4beed8){ut['logger']('[Fax][Message][Error][Updated]',_0x4beed8);})[_0x2eb4('0x39')](function(_0x420595){ut[_0x2eb4('0x42')](_0x2eb4('0x43'),_0x420595);});}else{ut[_0x2eb4('0x42')](_0x2eb4('0x44'));}}Fax[_0x2eb4('0x25')][_0x2eb4('0x45')]=function(_0x54d584,_0x3144eb,_0x3b9b95){var _0xae74c7=this;var _0x4419c6={};if(_0x3144eb){_0x4419c6={'read':_0x3144eb};}else{_0x4419c6={'failMessage':_0x3b9b95};}if(this['actions'][_0x54d584][_0x2eb4('0x40')]){faxMessage[_0x2eb4('0x41')](this[_0x2eb4('0x11')][_0x54d584]['AttachmentId'],_0x4419c6)[_0x2eb4('0x38')](function(_0x1734da){ut['logger'](_0x2eb4('0x46'),_0x1734da);})['catch'](function(_0x4d90b7){ut[_0x2eb4('0x42')]('[Fax][Message][NoUpdate1]',_0x4d90b7);})[_0x2eb4('0x47')](function(){delete _0xae74c7['channels'][_0x54d584];delete _0xae74c7[_0x2eb4('0x11')][_0x54d584];});}else{ut[_0x2eb4('0x42')](_0x2eb4('0x48'));delete this[_0x2eb4('0xe')][_0x54d584];delete this[_0x2eb4('0x11')][_0x54d584];}};Fax['prototype'][_0x2eb4('0x1c')]=function(_0x49866c){var _0x5ab7f8=this;if(this[_0x2eb4('0xe')][_0x49866c[_0x2eb4('0x20')]]){if(this[_0x2eb4('0x11')][_0x49866c['uniqueid']]){this[_0x2eb4('0xe')][_0x49866c[_0x2eb4('0x20')]]['id']=this[_0x2eb4('0x11')][_0x49866c['uniqueid']]['id'];this[_0x2eb4('0xe')][_0x49866c[_0x2eb4('0x20')]][_0x2eb4('0x22')]=this[_0x2eb4('0x11')][_0x49866c['uniqueid']][_0x2eb4('0x22')];}logger[_0x2eb4('0x23')](_0x49866c[_0x2eb4('0x20')],this[_0x2eb4('0x11')][_0x49866c['uniqueid']]?_0x2eb4('0x49'):'\x20hangup\x20faxRiceive\x20',JSON[_0x2eb4('0x3b')](this[_0x2eb4('0xe')][_0x49866c[_0x2eb4('0x20')]]));if(this[_0x2eb4('0x11')][_0x49866c[_0x2eb4('0x20')]]){if(this[_0x2eb4('0xe')][_0x49866c['uniqueid']]['faxpages']>0x0&&this['channels'][_0x49866c['uniqueid']][_0x2eb4('0x4a')]===_0x2eb4('0x4b')){this['updateStatus'](_0x49866c['uniqueid'],!![]);}else{this[_0x2eb4('0x45')](_0x49866c[_0x2eb4('0x20')],![],this['channels'][_0x49866c['uniqueid']][_0x2eb4('0x4c')]?_0x2eb4('0x4d')+this['channels'][_0x49866c[_0x2eb4('0x20')]][_0x2eb4('0x4c')]:'SENDING\x20FAILED');}}}};Fax[_0x2eb4('0x25')][_0x2eb4('0x4e')]=function(_0x5366b9){var _0x431747=this;return new BPromise(function(_0x302efe,_0x442716){_0x431747[_0x2eb4('0x4f')](_0x5366b9,_0x431747[_0x2eb4('0xf')][_0x5366b9[_0x2eb4('0x50')]])[_0x2eb4('0x38')](function(_0x455d7f){ut[_0x2eb4('0x42')]('[Fax][execOriginate][success]',_0x455d7f);_0x302efe(ut['message']('Fax\x20received'));})[_0x2eb4('0x39')](function(_0x39164c){ut[_0x2eb4('0x42')](_0x2eb4('0x51'),_0x39164c);updateStatus(_0x5366b9);_0x442716(ut['message'](_0x2eb4('0x52')));});});};Fax['prototype'][_0x2eb4('0x53')]=function(_0x205c2b){var _0x1ba524=this;return new BPromise(function(_0x1db3ad,_0x56fe02){var _0x46ed63=_0x1ba524[_0x2eb4('0x54')](_0x1ba524[_0x2eb4('0xf')][_0x205c2b[_0x2eb4('0x50')]][_0x2eb4('0x55')],_0x205c2b);if(_0x46ed63[_0x2eb4('0x56')]){_0x1db3ad(ut[_0x2eb4('0x34')](_0x2eb4('0x57')));}else{_0x56fe02(ut[_0x2eb4('0x34')](_0x46ed63['message']));}});};function originate(_0x4cc0ae,_0x5a6b66,_0x57ff0a){return new BPromise(function(_0x5be53a,_0x367eb0){if(_0x57ff0a){var _0x3d7557=util[_0x2eb4('0x58')]('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'](_0x4cc0ae['path'])['name'],_0x4cc0ae[_0x2eb4('0x59')]);gs['execute'](_0x3d7557)['then'](function(){_0x4cc0ae[_0x2eb4('0x59')]=util['format'](_0x2eb4('0x5a'),path['parse'](_0x4cc0ae[_0x2eb4('0x59')])['dir'],path[_0x2eb4('0x36')](_0x4cc0ae[_0x2eb4('0x59')])[_0x2eb4('0x22')]);_0x5a6b66[_0x2eb4('0x5b')]=_0x4cc0ae[_0x2eb4('0x59')];ut[_0x2eb4('0x42')]('Convert\x20pdf\x20to\x20tif','');ami[_0x2eb4('0x5c')](ut[_0x2eb4('0x5d')](_0x4cc0ae,_0x5a6b66))[_0x2eb4('0x38')](function(_0x9e717d){_0x5be53a(_0x9e717d);})[_0x2eb4('0x39')](function(_0xfa2c34){_0x367eb0(_0xfa2c34);});})[_0x2eb4('0x39')](function(_0x456590){_0x367eb0(_0x456590);});}else{ami[_0x2eb4('0x5c')](ut[_0x2eb4('0x5d')](_0x4cc0ae,_0x5a6b66))[_0x2eb4('0x38')](function(_0xd6b302){_0x5be53a(_0xd6b302);})[_0x2eb4('0x39')](function(_0x1505f1){_0x367eb0(_0x1505f1);});}});}Fax[_0x2eb4('0x25')][_0x2eb4('0x4f')]=function(_0x30aa61,_0x32aaaa){var _0x36f881=this;return new BPromise(function(_0x4cb24d,_0x5a16fa){var _0x4f68a6=uuid['v4']();var _0x59391f=ut[_0x2eb4('0x5e')](_0x30aa61,_0x32aaaa);_0x36f881[_0x2eb4('0x11')][_0x4f68a6]=new Action(_0x4f68a6,_0x32aaaa,_0x30aa61);var _0x1211b1=_0x36f881[_0x2eb4('0x11')][_0x4f68a6];if(path[_0x2eb4('0x36')](_0x30aa61[_0x2eb4('0x59')])[_0x2eb4('0x5f')]===_0x2eb4('0x37')){originate(_0x1211b1,_0x59391f,!![])['then'](function(_0x3c8e53){_0x4cb24d(_0x3c8e53);})[_0x2eb4('0x39')](function(_0x4f0c98){_0x5a16fa(_0x4f0c98);});}else{originate(_0x1211b1,_0x59391f,![])[_0x2eb4('0x38')](function(_0x296053){_0x4cb24d(_0x296053);})['catch'](function(_0x1a11ca){_0x5a16fa(_0x1a11ca);});}});};Fax[_0x2eb4('0x25')][_0x2eb4('0x60')]=function(_0x59ac74){return!_['isNil'](_0x59ac74)&&!_[_0x2eb4('0x61')](_0x59ac74[_0x2eb4('0x22')])&&!_[_0x2eb4('0x61')](_0x59ac74[_0x2eb4('0x62')])&&_0x59ac74[_0x2eb4('0x62')]&&!_[_0x2eb4('0x61')](this[_0x2eb4('0x10')][util[_0x2eb4('0x58')](_0x2eb4('0x63'),_0x59ac74[_0x2eb4('0x22')])])&&!_[_0x2eb4('0x61')](this[_0x2eb4('0x10')][util[_0x2eb4('0x58')](_0x2eb4('0x63'),_0x59ac74[_0x2eb4('0x22')])][_0x2eb4('0x64')])&&(this[_0x2eb4('0x10')][util[_0x2eb4('0x58')](_0x2eb4('0x63'),_0x59ac74[_0x2eb4('0x22')])][_0x2eb4('0x64')]===_0x2eb4('0x65')||this[_0x2eb4('0x10')][util[_0x2eb4('0x58')](_0x2eb4('0x63'),_0x59ac74[_0x2eb4('0x22')])][_0x2eb4('0x64')]===_0x2eb4('0x66'));};Fax['prototype']['checkTrunk']=function(_0x272723,_0x6c9b7){if(!this[_0x2eb4('0x60')](_0x272723)){ut['logger']('[Fax][checkTrunk][Trunk\x20not\x20work]',_['isNil'](_0x272723)?'':_0x272723['name']+_0x2eb4('0x67'));return{'isValid':![],'message':'Trunk\x20not\x20working'};}if(_[_0x2eb4('0x61')](_0x6c9b7[_0x2eb4('0x5')])){ut[_0x2eb4('0x42')]('[Fax][checkTrunk][Empty\x20Fax]',JSON[_0x2eb4('0x3b')](_0x6c9b7));return{'isValid':![],'message':_0x2eb4('0x68')};}if(_[_0x2eb4('0x61')](_0x6c9b7[_0x2eb4('0x59')])){ut[_0x2eb4('0x42')]('[Fax][checkTrunk][Empty\x20path]',JSON[_0x2eb4('0x3b')](_0x6c9b7));return{'isValid':![],'message':_0x2eb4('0x69')};}return{'isValid':!![],'message':'Is\x20Valid'};};module[_0x2eb4('0x6a')]=Fax;
\ No newline at end of file
+var _0x5aad=['[Fax][checkTrunk][Empty\x20path]','Empty\x20path','Is\x20Valid','exports','lodash','bluebird','moment','path','tiff2pdf','./util/gs','fax','./rpcDb','./channel','./action','../rpc/attachment','../rpc/faxMessage','channels','faxAccounts','trunks','actions','newchannel','syncNewchannel','bind','syncVarSet','newstate','syncNewState','newexten','syncNewExten','faxstatus','syncFaxStatus','receivefax','syncReceiveFax','hangup','syncHangup','originateresponse','context','hasOwnProperty','exten','localstationid','uniqueid','channel','name','\x20syncNewchannel\x20','info','prototype','variable','value','channelstate','channelstatedesc','operation','status','filename','\x20syncFaxStatus\x20','remotestationid','pagestransferred','resolution','transferrate','calleridnum','/var/opt/motion2/server/files/attachments/','\x20result\x20conversion\x20file\x20','create','parse','.pdf','application/pdf','then','notify','catch','stringify','error','syncOriginateResponse','merge','pick','response','reason','update','AttachmentId','SENDING\x20FAILED\x20','logger','[Fax][Message][Error][Updated]','[Fax][Message][Error][NoUpdate1]','[Fax][Message][Error][NoUpdate2]','updateStatus','[Fax][Message][Updated]','finally','[Fax][Message][NoUpdate2]','\x20hangup\x20sendFile\x20','\x20hangup\x20faxRiceive\x20','SENDING\x20FAILED:\x20','SENDING\x20FAILED','FaxAccountId','[Fax][execOriginate][success]','message','[Fax][execOriginate][failure]','checkAfterSend','Trunk\x20Reachable','execute','format','%s/%s.tif','XMF-PATH','Action','variablesAction','execOriginate','addVariables','ext','isNil','active','SIP/%s','reachable','unmonitored','checkTrunk','isTrunkReachable','[Fax][checkTrunk][Trunk\x20not\x20work]','\x20Trunk\x20is\x20not\x20active','Trunk\x20not\x20working','Empty\x20Fax'];(function(_0x229ac9,_0x306c05){var _0x5760d7=function(_0xfa95b5){while(--_0xfa95b5){_0x229ac9['push'](_0x229ac9['shift']());}};_0x5760d7(++_0x306c05);}(_0x5aad,0x1d0));var _0xd5aa=function(_0x5c15dc,_0x4e9854){_0x5c15dc=_0x5c15dc-0x0;var _0x53c99c=_0x5aad[_0x5c15dc];return _0x53c99c;};'use strict';var util=require('util');var _=require(_0xd5aa('0x0'));var BPromise=require(_0xd5aa('0x1'));var uuid=require('uuid');var moment=require(_0xd5aa('0x2'));var path=require(_0xd5aa('0x3'));var tiff2pdf=require(_0xd5aa('0x4'));var gs=require(_0xd5aa('0x5'));var logger=require('../../../config/logger')(_0xd5aa('0x6'));var ami=require('../ami');var rpcDb=require(_0xd5aa('0x7'));var Channel=require(_0xd5aa('0x8'));var ut=require('./util/util');var Action=require(_0xd5aa('0x9'));var faxAccount=require('../rpc/faxAccount');var attachment=require(_0xd5aa('0xa'));var faxMessage=require(_0xd5aa('0xb'));function Fax(_0x5393ff){this[_0xd5aa('0xc')]={};this[_0xd5aa('0xd')]=_0x5393ff[_0xd5aa('0xd')];this[_0xd5aa('0xe')]=_0x5393ff[_0xd5aa('0xe')];this[_0xd5aa('0xf')]={};ami['on'](_0xd5aa('0x10'),this[_0xd5aa('0x11')][_0xd5aa('0x12')](this));ami['on']('varset',this[_0xd5aa('0x13')]['bind'](this));ami['on'](_0xd5aa('0x14'),this[_0xd5aa('0x15')][_0xd5aa('0x12')](this));ami['on'](_0xd5aa('0x16'),this[_0xd5aa('0x17')][_0xd5aa('0x12')](this));ami['on'](_0xd5aa('0x18'),this[_0xd5aa('0x19')][_0xd5aa('0x12')](this));ami['on'](_0xd5aa('0x1a'),this[_0xd5aa('0x1b')]['bind'](this));ami['on'](_0xd5aa('0x1c'),this[_0xd5aa('0x1d')][_0xd5aa('0x12')](this));ami['on'](_0xd5aa('0x1e'),this['syncOriginateResponse'][_0xd5aa('0x12')](this));}Fax['prototype'][_0xd5aa('0x11')]=function(_0x58560b){if(_0x58560b[_0xd5aa('0x1f')]==='from-voip-provider'){for(var _0x26ccb4 in this[_0xd5aa('0xd')]){if(this['faxAccounts'][_0xd5aa('0x20')](_0x26ccb4)){if(_0x58560b[_0xd5aa('0x21')]===this['faxAccounts'][_0x26ccb4][_0xd5aa('0x22')]){this[_0xd5aa('0xc')][_0x58560b[_0xd5aa('0x23')]]={};this[_0xd5aa('0xc')][_0x58560b[_0xd5aa('0x23')]][_0xd5aa('0x24')]=_0x58560b[_0xd5aa('0x24')];this[_0xd5aa('0xc')][_0x58560b[_0xd5aa('0x23')]]['id']=this[_0xd5aa('0xd')][_0x26ccb4]['id'];this[_0xd5aa('0xc')][_0x58560b['uniqueid']][_0xd5aa('0x25')]=this[_0xd5aa('0xd')][_0x26ccb4][_0xd5aa('0x25')];logger['info'](_0x58560b[_0xd5aa('0x23')],_0xd5aa('0x26'));}}}}if(this[_0xd5aa('0xf')][_0x58560b[_0xd5aa('0x23')]]){this['channels'][_0x58560b[_0xd5aa('0x23')]]={};this['channels'][_0x58560b[_0xd5aa('0x23')]][_0xd5aa('0x24')]=_0x58560b[_0xd5aa('0x24')];logger[_0xd5aa('0x27')](_0x58560b[_0xd5aa('0x23')],'\x20syncNewchannel\x20');}};Fax[_0xd5aa('0x28')][_0xd5aa('0x13')]=function(_0x3ae51c){if(this[_0xd5aa('0xc')][_0x3ae51c[_0xd5aa('0x23')]]){for(var _0x2d3af9 in _0x3ae51c[_0xd5aa('0x29')]){if(_0x3ae51c[_0xd5aa('0x29')][_0xd5aa('0x20')](_0x2d3af9)){this[_0xd5aa('0xc')][_0x3ae51c[_0xd5aa('0x23')]][_0x2d3af9]=_0x3ae51c[_0xd5aa('0x2a')];}}}};Fax[_0xd5aa('0x28')][_0xd5aa('0x15')]=function(_0x2b53ed){if(this[_0xd5aa('0xc')][_0x2b53ed['uniqueid']]){this[_0xd5aa('0xc')][_0x2b53ed[_0xd5aa('0x23')]][_0xd5aa('0x2b')]=_0x2b53ed[_0xd5aa('0x2b')];this[_0xd5aa('0xc')][_0x2b53ed[_0xd5aa('0x23')]][_0xd5aa('0x2c')]=_0x2b53ed[_0xd5aa('0x2c')];}};Fax[_0xd5aa('0x28')][_0xd5aa('0x17')]=function(_0x22904a){if(this[_0xd5aa('0xc')][_0x22904a[_0xd5aa('0x23')]]){for(var _0x509f5e in _0x22904a[_0xd5aa('0x29')]){if(_0x22904a['variable']['hasOwnProperty'](_0x509f5e)){this[_0xd5aa('0xc')][_0x22904a[_0xd5aa('0x23')]][_0x509f5e]=_0x22904a['value'];}}}};Fax['prototype'][_0xd5aa('0x19')]=function(_0x35b4de){if(this['channels'][_0x35b4de[_0xd5aa('0x23')]]){this[_0xd5aa('0xc')][_0x35b4de[_0xd5aa('0x23')]][_0xd5aa('0x2d')]=_0x35b4de['operation'];this[_0xd5aa('0xc')][_0x35b4de[_0xd5aa('0x23')]]['status']=_0x35b4de[_0xd5aa('0x2e')];this[_0xd5aa('0xc')][_0x35b4de[_0xd5aa('0x23')]][_0xd5aa('0x22')]=_0x35b4de['localstationid'];this[_0xd5aa('0xc')][_0x35b4de['uniqueid']][_0xd5aa('0x2f')]=_0x35b4de[_0xd5aa('0x2f')];logger[_0xd5aa('0x27')](_0x35b4de[_0xd5aa('0x23')],_0xd5aa('0x30'));}};Fax[_0xd5aa('0x28')][_0xd5aa('0x1b')]=function(_0x3d476d){var _0x3660db=this;if(this['channels'][_0x3d476d['uniqueid']]){var _0x3d9fe6=this[_0xd5aa('0xc')][_0x3d476d[_0xd5aa('0x23')]]['id'];this[_0xd5aa('0xc')][_0x3d476d[_0xd5aa('0x23')]][_0xd5aa('0x31')]=_0x3d476d[_0xd5aa('0x31')];this[_0xd5aa('0xc')][_0x3d476d[_0xd5aa('0x23')]][_0xd5aa('0x32')]=_0x3d476d[_0xd5aa('0x32')];this[_0xd5aa('0xc')][_0x3d476d['uniqueid']]['localstationid']=_0x3d476d[_0xd5aa('0x22')];this[_0xd5aa('0xc')][_0x3d476d['uniqueid']][_0xd5aa('0x33')]=_0x3d476d['resolution'];this['channels'][_0x3d476d[_0xd5aa('0x23')]][_0xd5aa('0x34')]=_0x3d476d[_0xd5aa('0x34')];this[_0xd5aa('0xc')][_0x3d476d['uniqueid']][_0xd5aa('0x2f')]=_0x3d476d['filename'];this[_0xd5aa('0xc')][_0x3d476d['uniqueid']][_0xd5aa('0x35')]=_0x3d476d[_0xd5aa('0x35')];if(this[_0xd5aa('0xc')][_0x3d476d[_0xd5aa('0x23')]]['pagestransferred']>0x0){tiff2pdf(_0x3d476d[_0xd5aa('0x2f')],_0xd5aa('0x36'),function(_0x535ce4){logger['info'](_0x3d476d['uniqueid'],_0xd5aa('0x37'),_0x535ce4['message']);attachment[_0xd5aa('0x38')]({'name':path[_0xd5aa('0x39')](_0x3d476d[_0xd5aa('0x2f')])[_0xd5aa('0x25')],'basename':path[_0xd5aa('0x39')](_0x3d476d[_0xd5aa('0x2f')])['name']+_0xd5aa('0x3a'),'type':_0xd5aa('0x3b')})[_0xd5aa('0x3c')](function(_0xd55abf){faxAccount[_0xd5aa('0x3d')](_0x3d9fe6,{'from':_0x3d476d[_0xd5aa('0x35')],'mapKey':_0xd5aa('0x6'),'body':path[_0xd5aa('0x39')](_0x3d476d[_0xd5aa('0x2f')])[_0xd5aa('0x25')]+'.pdf','AttachmentId':_0xd55abf['id']})[_0xd5aa('0x3e')](function(_0x4c9ba2){logger['error'](_0x3d476d['uniqueid'],'\x20notify\x20',JSON[_0xd5aa('0x3f')](_0x4c9ba2));});})[_0xd5aa('0x3e')](function(_0x2599a4){logger[_0xd5aa('0x40')](_0x3d476d[_0xd5aa('0x23')],'\x20receiveFax\x20',JSON['stringify'](_0x2599a4));});});}logger[_0xd5aa('0x27')](_0x3d476d[_0xd5aa('0x23')],'\x20receiveFax\x20');}};Fax[_0xd5aa('0x28')][_0xd5aa('0x41')]=function(_0xc9109f){if(this[_0xd5aa('0xf')][_0xc9109f['uniqueid']]){_[_0xd5aa('0x42')](this[_0xd5aa('0xc')][_0xc9109f[_0xd5aa('0x23')]],_[_0xd5aa('0x43')](_0xc9109f,[_0xd5aa('0x44'),_0xd5aa('0x45')]));}};function updateStatus(_0x1cb6a2){if(_0x1cb6a2['AttachmentId']){faxMessage[_0xd5aa('0x46')](_0x1cb6a2[_0xd5aa('0x47')],{'failMessage':_0xd5aa('0x48')})[_0xd5aa('0x3c')](function(_0x5bd6ed){ut[_0xd5aa('0x49')](_0xd5aa('0x4a'),_0x5bd6ed);})[_0xd5aa('0x3e')](function(_0x5d99df){ut[_0xd5aa('0x49')](_0xd5aa('0x4b'),_0x5d99df);});}else{ut[_0xd5aa('0x49')](_0xd5aa('0x4c'));}}Fax['prototype'][_0xd5aa('0x4d')]=function(_0x3af4db,_0x439cc6,_0x82c048){var _0x31270d=this;var _0xd4ca7a={};if(_0x439cc6){_0xd4ca7a={'read':_0x439cc6};}else{_0xd4ca7a={'failMessage':_0x82c048};}if(this[_0xd5aa('0xf')][_0x3af4db][_0xd5aa('0x47')]){faxMessage[_0xd5aa('0x46')](this[_0xd5aa('0xf')][_0x3af4db][_0xd5aa('0x47')],_0xd4ca7a)[_0xd5aa('0x3c')](function(_0x4c9f5f){ut[_0xd5aa('0x49')](_0xd5aa('0x4e'),_0x4c9f5f);})[_0xd5aa('0x3e')](function(_0xdfcfd1){ut[_0xd5aa('0x49')]('[Fax][Message][NoUpdate1]',_0xdfcfd1);})[_0xd5aa('0x4f')](function(){delete _0x31270d[_0xd5aa('0xc')][_0x3af4db];delete _0x31270d[_0xd5aa('0xf')][_0x3af4db];});}else{ut['logger'](_0xd5aa('0x50'));delete this[_0xd5aa('0xc')][_0x3af4db];delete this['actions'][_0x3af4db];}};Fax[_0xd5aa('0x28')]['syncHangup']=function(_0x49d583){var _0x54e8bc=this;if(this[_0xd5aa('0xc')][_0x49d583['uniqueid']]){if(this['actions'][_0x49d583[_0xd5aa('0x23')]]){this[_0xd5aa('0xc')][_0x49d583[_0xd5aa('0x23')]]['id']=this['actions'][_0x49d583[_0xd5aa('0x23')]]['id'];this[_0xd5aa('0xc')][_0x49d583[_0xd5aa('0x23')]]['name']=this[_0xd5aa('0xf')][_0x49d583['uniqueid']][_0xd5aa('0x25')];}logger['info'](_0x49d583['uniqueid'],this[_0xd5aa('0xf')][_0x49d583['uniqueid']]?_0xd5aa('0x51'):_0xd5aa('0x52'),JSON[_0xd5aa('0x3f')](this[_0xd5aa('0xc')][_0x49d583[_0xd5aa('0x23')]]));if(this[_0xd5aa('0xf')][_0x49d583['uniqueid']]){if(this[_0xd5aa('0xc')][_0x49d583[_0xd5aa('0x23')]]['faxpages']>0x0&&this['channels'][_0x49d583[_0xd5aa('0x23')]]['faxstatus']==='SUCCESS'){this[_0xd5aa('0x4d')](_0x49d583[_0xd5aa('0x23')],!![]);}else{this[_0xd5aa('0x4d')](_0x49d583[_0xd5aa('0x23')],![],this[_0xd5aa('0xc')][_0x49d583[_0xd5aa('0x23')]]['faxstatusstring']?_0xd5aa('0x53')+this['channels'][_0x49d583['uniqueid']]['faxstatusstring']:_0xd5aa('0x54'));}}}};Fax[_0xd5aa('0x28')]['send']=function(_0x5b2322){var _0x53b19=this;return new BPromise(function(_0x345ebd,_0xd0869e){_0x53b19['execOriginate'](_0x5b2322,_0x53b19[_0xd5aa('0xd')][_0x5b2322[_0xd5aa('0x55')]])[_0xd5aa('0x3c')](function(_0x1f948d){ut[_0xd5aa('0x49')](_0xd5aa('0x56'),_0x1f948d);_0x345ebd(ut[_0xd5aa('0x57')]('Fax\x20received'));})['catch'](function(_0x3e0835){ut[_0xd5aa('0x49')](_0xd5aa('0x58'),_0x3e0835);updateStatus(_0x5b2322);_0xd0869e(ut[_0xd5aa('0x57')]('Fax\x20failed'));});});};Fax[_0xd5aa('0x28')][_0xd5aa('0x59')]=function(_0xb6349a){var _0x115e91=this;return new BPromise(function(_0x2a3480,_0x438617){var _0x33a106=_0x115e91['checkTrunk'](_0x115e91['faxAccounts'][_0xb6349a[_0xd5aa('0x55')]]['Trunk'],_0xb6349a);if(_0x33a106['isValid']){_0x2a3480(ut[_0xd5aa('0x57')](_0xd5aa('0x5a')));}else{_0x438617(ut[_0xd5aa('0x57')](_0x33a106[_0xd5aa('0x57')]));}});};function originate(_0x3e841d,_0x3ce670,_0x5eab75){return new BPromise(function(_0x27fa59,_0x2f5925){if(_0x5eab75){var _0x5cd3d7=util['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',path[_0xd5aa('0x39')](_0x3e841d[_0xd5aa('0x3')])['name'],_0x3e841d[_0xd5aa('0x3')]);gs[_0xd5aa('0x5b')](_0x5cd3d7)[_0xd5aa('0x3c')](function(){_0x3e841d['path']=util[_0xd5aa('0x5c')](_0xd5aa('0x5d'),path[_0xd5aa('0x39')](_0x3e841d[_0xd5aa('0x3')])['dir'],path[_0xd5aa('0x39')](_0x3e841d[_0xd5aa('0x3')])[_0xd5aa('0x25')]);_0x3ce670[_0xd5aa('0x5e')]=_0x3e841d[_0xd5aa('0x3')];ut[_0xd5aa('0x49')]('Convert\x20pdf\x20to\x20tif','');ami[_0xd5aa('0x5f')](ut[_0xd5aa('0x60')](_0x3e841d,_0x3ce670))[_0xd5aa('0x3c')](function(_0x17851c){_0x27fa59(_0x17851c);})['catch'](function(_0x3da074){_0x2f5925(_0x3da074);});})['catch'](function(_0x102df8){_0x2f5925(_0x102df8);});}else{ami[_0xd5aa('0x5f')](ut[_0xd5aa('0x60')](_0x3e841d,_0x3ce670))[_0xd5aa('0x3c')](function(_0x20ca92){_0x27fa59(_0x20ca92);})['catch'](function(_0x271f14){_0x2f5925(_0x271f14);});}});}Fax['prototype'][_0xd5aa('0x61')]=function(_0x270d31,_0x37d586){var _0x104962=this;return new BPromise(function(_0x4cf193,_0x243725){var _0x1eb4de=uuid['v4']();var _0x263588=ut[_0xd5aa('0x62')](_0x270d31,_0x37d586);_0x104962[_0xd5aa('0xf')][_0x1eb4de]=new Action(_0x1eb4de,_0x37d586,_0x270d31);var _0x5d1720=_0x104962[_0xd5aa('0xf')][_0x1eb4de];if(path[_0xd5aa('0x39')](_0x270d31[_0xd5aa('0x3')])[_0xd5aa('0x63')]===_0xd5aa('0x3a')){originate(_0x5d1720,_0x263588,!![])[_0xd5aa('0x3c')](function(_0x754795){_0x4cf193(_0x754795);})[_0xd5aa('0x3e')](function(_0x29d5a8){_0x243725(_0x29d5a8);});}else{originate(_0x5d1720,_0x263588,![])['then'](function(_0x4fe7dd){_0x4cf193(_0x4fe7dd);})['catch'](function(_0x2747c7){_0x243725(_0x2747c7);});}});};Fax[_0xd5aa('0x28')]['isTrunkReachable']=function(_0x454f0a){return!_[_0xd5aa('0x64')](_0x454f0a)&&!_[_0xd5aa('0x64')](_0x454f0a[_0xd5aa('0x25')])&&!_[_0xd5aa('0x64')](_0x454f0a[_0xd5aa('0x65')])&&_0x454f0a[_0xd5aa('0x65')]&&!_[_0xd5aa('0x64')](this[_0xd5aa('0xe')][util[_0xd5aa('0x5c')]('SIP/%s',_0x454f0a[_0xd5aa('0x25')])])&&!_[_0xd5aa('0x64')](this['trunks'][util[_0xd5aa('0x5c')](_0xd5aa('0x66'),_0x454f0a[_0xd5aa('0x25')])][_0xd5aa('0x2e')])&&(this[_0xd5aa('0xe')][util[_0xd5aa('0x5c')](_0xd5aa('0x66'),_0x454f0a[_0xd5aa('0x25')])]['status']===_0xd5aa('0x67')||this[_0xd5aa('0xe')][util[_0xd5aa('0x5c')](_0xd5aa('0x66'),_0x454f0a[_0xd5aa('0x25')])][_0xd5aa('0x2e')]===_0xd5aa('0x68'));};Fax[_0xd5aa('0x28')][_0xd5aa('0x69')]=function(_0x1be6a6,_0x44b46c){if(!this[_0xd5aa('0x6a')](_0x1be6a6)){ut[_0xd5aa('0x49')](_0xd5aa('0x6b'),_[_0xd5aa('0x64')](_0x1be6a6)?'':_0x1be6a6['name']+_0xd5aa('0x6c'));return{'isValid':![],'message':_0xd5aa('0x6d')};}if(_[_0xd5aa('0x64')](_0x44b46c[_0xd5aa('0x6')])){ut[_0xd5aa('0x49')]('[Fax][checkTrunk][Empty\x20Fax]',JSON[_0xd5aa('0x3f')](_0x44b46c));return{'isValid':![],'message':_0xd5aa('0x6e')};}if(_[_0xd5aa('0x64')](_0x44b46c[_0xd5aa('0x3')])){ut[_0xd5aa('0x49')](_0xd5aa('0x6f'),JSON['stringify'](_0x44b46c));return{'isValid':![],'message':_0xd5aa('0x70')};}return{'isValid':!![],'message':_0xd5aa('0x71')};};module[_0xd5aa('0x72')]=Fax;
\ No newline at end of file