Built motion from commit 56a37f2a.|2.6.21
[motion2.git] / server / services / ami / fax / index.js
index 2e23e11..6cd16a9 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xfad0=['\x20notify\x20','stringify','\x20receiveFax\x20','merge','pick','response','AttachmentId','update','SENDING\x20FAILED\x20','logger','[Fax][Message][Error][Updated]','[Fax][Message][Error][NoUpdate1]','[Fax][Message][Error][NoUpdate2]','updateStatus','[Fax][Message][Updated]','[Fax][Message][NoUpdate1]','finally','[Fax][Message][NoUpdate2]','\x20hangup\x20sendFile\x20','\x20hangup\x20faxRiceive\x20','faxpages','faxstatus','SUCCESS','faxstatusstring','SENDING\x20FAILED:\x20','SENDING\x20FAILED','send','execOriginate','FaxAccountId','Fax\x20received','[Fax][execOriginate][failure]','Fax\x20failed','checkAfterSend','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','path','execute','dir','XMF-PATH','Convert\x20pdf\x20to\x20tif','Action','variablesAction','addVariables','isTrunkReachable','isNil','active','SIP/%s','unmonitored','[Fax][checkTrunk][Trunk\x20not\x20working\x20correctly]','\x20Trunk\x20is\x20not\x20active','Trunk\x20not\x20working\x20correctly','Empty\x20Fax','[Fax][checkTrunk][Empty\x20path]','exports','lodash','uuid','moment','tiff2pdf','../../../config/logger','fax','../ami','./rpcDb','./channel','./util/util','./action','../rpc/faxAccount','../rpc/attachment','../rpc/faxMessage','channels','faxAccounts','trunks','newchannel','bind','varset','syncVarSet','newstate','syncNewState','syncNewExten','syncFaxStatus','receivefax','originateresponse','syncOriginateResponse','syncNewchannel','context','from-voip-provider','hasOwnProperty','exten','localstationid','uniqueid','channel','name','info','actions','\x20syncNewchannel\x20','variable','prototype','channelstate','channelstatedesc','value','status','filename','\x20syncFaxStatus\x20','remotestationid','pagestransferred','resolution','transferrate','calleridnum','/var/opt/motion2/server/files/attachments/','\x20result\x20conversion\x20file\x20','message','create','parse','then','.pdf','catch','error'];(function(_0xf30510,_0x1dabf0){var _0x149218=function(_0x16e3ad){while(--_0x16e3ad){_0xf30510['push'](_0xf30510['shift']());}};_0x149218(++_0x1dabf0);}(_0xfad0,0xb0));var _0x0fad=function(_0x5015f0,_0x587229){_0x5015f0=_0x5015f0-0x0;var _0x1d4aea=_0xfad0[_0x5015f0];return _0x1d4aea;};'use strict';var util=require('util');var _=require(_0x0fad('0x0'));var BPromise=require('bluebird');var uuid=require(_0x0fad('0x1'));var moment=require(_0x0fad('0x2'));var path=require('path');var tiff2pdf=require(_0x0fad('0x3'));var gs=require('./util/gs');var logger=require(_0x0fad('0x4'))(_0x0fad('0x5'));var ami=require(_0x0fad('0x6'));var rpcDb=require(_0x0fad('0x7'));var Channel=require(_0x0fad('0x8'));var ut=require(_0x0fad('0x9'));var Action=require(_0x0fad('0xa'));var faxAccount=require(_0x0fad('0xb'));var attachment=require(_0x0fad('0xc'));var faxMessage=require(_0x0fad('0xd'));function Fax(_0x10a816){this[_0x0fad('0xe')]={};this[_0x0fad('0xf')]=_0x10a816[_0x0fad('0xf')];this[_0x0fad('0x10')]=_0x10a816[_0x0fad('0x10')];this['actions']={};ami['on'](_0x0fad('0x11'),this['syncNewchannel'][_0x0fad('0x12')](this));ami['on'](_0x0fad('0x13'),this[_0x0fad('0x14')][_0x0fad('0x12')](this));ami['on'](_0x0fad('0x15'),this[_0x0fad('0x16')][_0x0fad('0x12')](this));ami['on']('newexten',this[_0x0fad('0x17')][_0x0fad('0x12')](this));ami['on']('faxstatus',this[_0x0fad('0x18')][_0x0fad('0x12')](this));ami['on'](_0x0fad('0x19'),this['syncReceiveFax']['bind'](this));ami['on']('hangup',this['syncHangup'][_0x0fad('0x12')](this));ami['on'](_0x0fad('0x1a'),this[_0x0fad('0x1b')]['bind'](this));}Fax['prototype'][_0x0fad('0x1c')]=function(_0x3c1604){if(_0x3c1604[_0x0fad('0x1d')]===_0x0fad('0x1e')){for(var _0x41e214 in this[_0x0fad('0xf')]){if(this['faxAccounts'][_0x0fad('0x1f')](_0x41e214)){if(_0x3c1604[_0x0fad('0x20')]===this[_0x0fad('0xf')][_0x41e214][_0x0fad('0x21')]){this[_0x0fad('0xe')][_0x3c1604[_0x0fad('0x22')]]={};this[_0x0fad('0xe')][_0x3c1604['uniqueid']][_0x0fad('0x23')]=_0x3c1604[_0x0fad('0x23')];this[_0x0fad('0xe')][_0x3c1604[_0x0fad('0x22')]]['id']=this[_0x0fad('0xf')][_0x41e214]['id'];this[_0x0fad('0xe')][_0x3c1604[_0x0fad('0x22')]][_0x0fad('0x24')]=this[_0x0fad('0xf')][_0x41e214][_0x0fad('0x24')];logger[_0x0fad('0x25')](_0x3c1604[_0x0fad('0x22')],'\x20syncNewchannel\x20');}}}}if(this[_0x0fad('0x26')][_0x3c1604[_0x0fad('0x22')]]){this['channels'][_0x3c1604[_0x0fad('0x22')]]={};this[_0x0fad('0xe')][_0x3c1604['uniqueid']][_0x0fad('0x23')]=_0x3c1604[_0x0fad('0x23')];logger[_0x0fad('0x25')](_0x3c1604['uniqueid'],_0x0fad('0x27'));}};Fax['prototype'][_0x0fad('0x14')]=function(_0xdb5e95){if(this[_0x0fad('0xe')][_0xdb5e95[_0x0fad('0x22')]]){for(var _0x463ea9 in _0xdb5e95[_0x0fad('0x28')]){if(_0xdb5e95[_0x0fad('0x28')][_0x0fad('0x1f')](_0x463ea9)){this[_0x0fad('0xe')][_0xdb5e95[_0x0fad('0x22')]][_0x463ea9]=_0xdb5e95['value'];}}}};Fax[_0x0fad('0x29')][_0x0fad('0x16')]=function(_0x18547c){if(this[_0x0fad('0xe')][_0x18547c['uniqueid']]){this[_0x0fad('0xe')][_0x18547c[_0x0fad('0x22')]][_0x0fad('0x2a')]=_0x18547c['channelstate'];this['channels'][_0x18547c[_0x0fad('0x22')]]['channelstatedesc']=_0x18547c[_0x0fad('0x2b')];}};Fax[_0x0fad('0x29')]['syncNewExten']=function(_0x34554f){if(this[_0x0fad('0xe')][_0x34554f[_0x0fad('0x22')]]){for(var _0x52e58d in _0x34554f[_0x0fad('0x28')]){if(_0x34554f[_0x0fad('0x28')][_0x0fad('0x1f')](_0x52e58d)){this[_0x0fad('0xe')][_0x34554f[_0x0fad('0x22')]][_0x52e58d]=_0x34554f[_0x0fad('0x2c')];}}}};Fax[_0x0fad('0x29')][_0x0fad('0x18')]=function(_0x1c743e){if(this[_0x0fad('0xe')][_0x1c743e[_0x0fad('0x22')]]){this[_0x0fad('0xe')][_0x1c743e['uniqueid']]['operation']=_0x1c743e['operation'];this[_0x0fad('0xe')][_0x1c743e[_0x0fad('0x22')]][_0x0fad('0x2d')]=_0x1c743e[_0x0fad('0x2d')];this[_0x0fad('0xe')][_0x1c743e[_0x0fad('0x22')]][_0x0fad('0x21')]=_0x1c743e[_0x0fad('0x21')];this[_0x0fad('0xe')][_0x1c743e['uniqueid']][_0x0fad('0x2e')]=_0x1c743e['filename'];logger[_0x0fad('0x25')](_0x1c743e[_0x0fad('0x22')],_0x0fad('0x2f'));}};Fax[_0x0fad('0x29')]['syncReceiveFax']=function(_0xaead14){var _0x4aa140=this;if(this[_0x0fad('0xe')][_0xaead14['uniqueid']]){var _0x532d9d=this['channels'][_0xaead14[_0x0fad('0x22')]]['id'];this['channels'][_0xaead14[_0x0fad('0x22')]]['remotestationid']=_0xaead14[_0x0fad('0x30')];this['channels'][_0xaead14[_0x0fad('0x22')]][_0x0fad('0x31')]=_0xaead14[_0x0fad('0x31')];this[_0x0fad('0xe')][_0xaead14[_0x0fad('0x22')]]['localstationid']=_0xaead14['localstationid'];this['channels'][_0xaead14[_0x0fad('0x22')]][_0x0fad('0x32')]=_0xaead14[_0x0fad('0x32')];this[_0x0fad('0xe')][_0xaead14['uniqueid']][_0x0fad('0x33')]=_0xaead14[_0x0fad('0x33')];this[_0x0fad('0xe')][_0xaead14[_0x0fad('0x22')]][_0x0fad('0x2e')]=_0xaead14[_0x0fad('0x2e')];this[_0x0fad('0xe')][_0xaead14[_0x0fad('0x22')]][_0x0fad('0x34')]=_0xaead14[_0x0fad('0x34')];if(this['channels'][_0xaead14[_0x0fad('0x22')]][_0x0fad('0x31')]>0x0){tiff2pdf(_0xaead14['filename'],_0x0fad('0x35'),function(_0x40755c){logger['info'](_0xaead14[_0x0fad('0x22')],_0x0fad('0x36'),_0x40755c[_0x0fad('0x37')]);attachment[_0x0fad('0x38')]({'name':path[_0x0fad('0x39')](_0xaead14[_0x0fad('0x2e')])[_0x0fad('0x24')],'basename':path[_0x0fad('0x39')](_0xaead14[_0x0fad('0x2e')])[_0x0fad('0x24')]+'.pdf','type':'application/pdf'})[_0x0fad('0x3a')](function(_0x4c52af){faxAccount['notify'](_0x532d9d,{'from':_0xaead14['calleridnum'],'mapKey':_0x0fad('0x5'),'body':path['parse'](_0xaead14['filename'])[_0x0fad('0x24')]+_0x0fad('0x3b'),'AttachmentId':_0x4c52af['id']})[_0x0fad('0x3c')](function(_0x5abd91){logger[_0x0fad('0x3d')](_0xaead14[_0x0fad('0x22')],_0x0fad('0x3e'),JSON[_0x0fad('0x3f')](_0x5abd91));});})['catch'](function(_0x541e35){logger[_0x0fad('0x3d')](_0xaead14['uniqueid'],'\x20receiveFax\x20',JSON[_0x0fad('0x3f')](_0x541e35));});});}logger[_0x0fad('0x25')](_0xaead14[_0x0fad('0x22')],_0x0fad('0x40'));}};Fax[_0x0fad('0x29')][_0x0fad('0x1b')]=function(_0x1161c7){if(this[_0x0fad('0x26')][_0x1161c7['uniqueid']]){_[_0x0fad('0x41')](this[_0x0fad('0xe')][_0x1161c7[_0x0fad('0x22')]],_[_0x0fad('0x42')](_0x1161c7,[_0x0fad('0x43'),'reason']));}};function updateStatus(_0x100087){if(_0x100087[_0x0fad('0x44')]){faxMessage[_0x0fad('0x45')](_0x100087['AttachmentId'],{'failMessage':_0x0fad('0x46')})[_0x0fad('0x3a')](function(_0x4fec67){ut[_0x0fad('0x47')](_0x0fad('0x48'),_0x4fec67);})[_0x0fad('0x3c')](function(_0x5a9c06){ut[_0x0fad('0x47')](_0x0fad('0x49'),_0x5a9c06);});}else{ut['logger'](_0x0fad('0x4a'));}}Fax[_0x0fad('0x29')][_0x0fad('0x4b')]=function(_0x5d7999,_0x50ffc5,_0x2de1a6){var _0x5428e5=this;var _0x38b1ae={};if(_0x50ffc5){_0x38b1ae={'read':_0x50ffc5};}else{_0x38b1ae={'failMessage':_0x2de1a6};}if(this[_0x0fad('0x26')][_0x5d7999][_0x0fad('0x44')]){faxMessage[_0x0fad('0x45')](this['actions'][_0x5d7999]['AttachmentId'],_0x38b1ae)[_0x0fad('0x3a')](function(_0x4ad50b){ut['logger'](_0x0fad('0x4c'),_0x4ad50b);})['catch'](function(_0x2c522e){ut[_0x0fad('0x47')](_0x0fad('0x4d'),_0x2c522e);})[_0x0fad('0x4e')](function(){delete _0x5428e5[_0x0fad('0xe')][_0x5d7999];delete _0x5428e5['actions'][_0x5d7999];});}else{ut['logger'](_0x0fad('0x4f'));delete this['channels'][_0x5d7999];delete this[_0x0fad('0x26')][_0x5d7999];}};Fax[_0x0fad('0x29')]['syncHangup']=function(_0x5edfca){var _0x200edf=this;if(this[_0x0fad('0xe')][_0x5edfca[_0x0fad('0x22')]]){if(this[_0x0fad('0x26')][_0x5edfca[_0x0fad('0x22')]]){this['channels'][_0x5edfca['uniqueid']]['id']=this[_0x0fad('0x26')][_0x5edfca[_0x0fad('0x22')]]['id'];this[_0x0fad('0xe')][_0x5edfca[_0x0fad('0x22')]][_0x0fad('0x24')]=this[_0x0fad('0x26')][_0x5edfca[_0x0fad('0x22')]]['name'];}logger[_0x0fad('0x25')](_0x5edfca[_0x0fad('0x22')],this[_0x0fad('0x26')][_0x5edfca[_0x0fad('0x22')]]?_0x0fad('0x50'):_0x0fad('0x51'),JSON[_0x0fad('0x3f')](this[_0x0fad('0xe')][_0x5edfca[_0x0fad('0x22')]]));if(this[_0x0fad('0x26')][_0x5edfca[_0x0fad('0x22')]]){if(this[_0x0fad('0xe')][_0x5edfca[_0x0fad('0x22')]][_0x0fad('0x52')]>0x0&&this[_0x0fad('0xe')][_0x5edfca['uniqueid']][_0x0fad('0x53')]===_0x0fad('0x54')){this[_0x0fad('0x4b')](_0x5edfca['uniqueid'],!![]);}else{this['updateStatus'](_0x5edfca[_0x0fad('0x22')],![],this[_0x0fad('0xe')][_0x5edfca[_0x0fad('0x22')]][_0x0fad('0x55')]?_0x0fad('0x56')+this[_0x0fad('0xe')][_0x5edfca['uniqueid']][_0x0fad('0x55')]:_0x0fad('0x57'));}}}};Fax['prototype'][_0x0fad('0x58')]=function(_0x53a8cf){var _0x4551ee=this;return new BPromise(function(_0x4af644,_0x231a57){_0x4551ee[_0x0fad('0x59')](_0x53a8cf,_0x4551ee[_0x0fad('0xf')][_0x53a8cf[_0x0fad('0x5a')]])[_0x0fad('0x3a')](function(_0x344d86){ut[_0x0fad('0x47')]('[Fax][execOriginate][success]',_0x344d86);_0x4af644(ut['message'](_0x0fad('0x5b')));})[_0x0fad('0x3c')](function(_0x4af433){ut['logger'](_0x0fad('0x5c'),_0x4af433);updateStatus(_0x53a8cf);_0x231a57(ut[_0x0fad('0x37')](_0x0fad('0x5d')));});});};Fax[_0x0fad('0x29')][_0x0fad('0x5e')]=function(_0x3df036){var _0x380a22=this;return new BPromise(function(_0x532c5c,_0x19c720){var _0x5de0a8=_0x380a22[_0x0fad('0x5f')](_0x380a22[_0x0fad('0xf')][_0x3df036[_0x0fad('0x5a')]]['Trunk'],_0x3df036);if(_0x5de0a8[_0x0fad('0x60')]){_0x532c5c(ut[_0x0fad('0x37')](_0x0fad('0x61')));}else{_0x19c720(ut[_0x0fad('0x37')](_0x5de0a8[_0x0fad('0x37')]));}});};function originate(_0x1ea2f5,_0xd8a1d8,_0xe04af6){return new BPromise(function(_0x5f241b,_0x3b7683){if(_0xe04af6){var _0x25cae6=util[_0x0fad('0x62')](_0x0fad('0x63'),path['parse'](_0x1ea2f5['path'])['name'],_0x1ea2f5[_0x0fad('0x64')]);gs[_0x0fad('0x65')](_0x25cae6)[_0x0fad('0x3a')](function(){_0x1ea2f5[_0x0fad('0x64')]=util['format']('%s/%s.tif',path['parse'](_0x1ea2f5['path'])[_0x0fad('0x66')],path[_0x0fad('0x39')](_0x1ea2f5[_0x0fad('0x64')])[_0x0fad('0x24')]);_0xd8a1d8[_0x0fad('0x67')]=_0x1ea2f5[_0x0fad('0x64')];ut[_0x0fad('0x47')](_0x0fad('0x68'),'');ami['Action'](ut['variablesAction'](_0x1ea2f5,_0xd8a1d8))['then'](function(_0x32cab2){_0x5f241b(_0x32cab2);})[_0x0fad('0x3c')](function(_0x1c2b26){_0x3b7683(_0x1c2b26);});})[_0x0fad('0x3c')](function(_0x3f1581){_0x3b7683(_0x3f1581);});}else{ami[_0x0fad('0x69')](ut[_0x0fad('0x6a')](_0x1ea2f5,_0xd8a1d8))[_0x0fad('0x3a')](function(_0x1f8580){_0x5f241b(_0x1f8580);})['catch'](function(_0x3e0ece){_0x3b7683(_0x3e0ece);});}});}Fax[_0x0fad('0x29')]['execOriginate']=function(_0x3b121f,_0x3e62f6){var _0x27f790=this;return new BPromise(function(_0x16ef74,_0x4ea4a4){var _0x5218dd=uuid['v4']();var _0x40ae64=ut[_0x0fad('0x6b')](_0x3b121f,_0x3e62f6);_0x27f790['actions'][_0x5218dd]=new Action(_0x5218dd,_0x3e62f6,_0x3b121f);var _0x3ed777=_0x27f790['actions'][_0x5218dd];if(path[_0x0fad('0x39')](_0x3b121f[_0x0fad('0x64')])['ext']==='.pdf'){originate(_0x3ed777,_0x40ae64,!![])[_0x0fad('0x3a')](function(_0x6e9f9){_0x16ef74(_0x6e9f9);})[_0x0fad('0x3c')](function(_0x172b28){_0x4ea4a4(_0x172b28);});}else{originate(_0x3ed777,_0x40ae64,![])[_0x0fad('0x3a')](function(_0x5b9892){_0x16ef74(_0x5b9892);})[_0x0fad('0x3c')](function(_0x58c8d7){_0x4ea4a4(_0x58c8d7);});}});};Fax[_0x0fad('0x29')][_0x0fad('0x6c')]=function(_0x40cb56){return!_[_0x0fad('0x6d')](_0x40cb56)&&!_[_0x0fad('0x6d')](_0x40cb56[_0x0fad('0x24')])&&!_['isNil'](_0x40cb56[_0x0fad('0x6e')])&&_0x40cb56[_0x0fad('0x6e')]&&!_[_0x0fad('0x6d')](this[_0x0fad('0x10')][util['format']('SIP/%s',_0x40cb56['name'])])&&!_[_0x0fad('0x6d')](this['trunks'][util['format'](_0x0fad('0x6f'),_0x40cb56['name'])][_0x0fad('0x2d')])&&(this[_0x0fad('0x10')][util[_0x0fad('0x62')](_0x0fad('0x6f'),_0x40cb56['name'])][_0x0fad('0x2d')]==='reachable'||this[_0x0fad('0x10')][util[_0x0fad('0x62')](_0x0fad('0x6f'),_0x40cb56['name'])][_0x0fad('0x2d')]===_0x0fad('0x70'));};Fax[_0x0fad('0x29')][_0x0fad('0x5f')]=function(_0x290c02,_0x2d4786){if(!this[_0x0fad('0x6c')](_0x290c02)){ut[_0x0fad('0x47')](_0x0fad('0x71'),_[_0x0fad('0x6d')](_0x290c02)?'':_0x290c02['name']+_0x0fad('0x72'));return{'isValid':![],'message':_0x0fad('0x73')};}if(_['isNil'](_0x2d4786[_0x0fad('0x5')])){ut['logger']('[Fax][checkTrunk][Empty\x20Fax]',JSON[_0x0fad('0x3f')](_0x2d4786));return{'isValid':![],'message':_0x0fad('0x74')};}if(_['isNil'](_0x2d4786[_0x0fad('0x64')])){ut[_0x0fad('0x47')](_0x0fad('0x75'),JSON['stringify'](_0x2d4786));return{'isValid':![],'message':'Empty\x20path'};}return{'isValid':!![],'message':'Is\x20Valid'};};module[_0x0fad('0x76')]=Fax;
\ No newline at end of file
+var _0xa0f2=['SENDING\x20FAILED\x20','[Fax][Message][Error][Updated]','logger','[Fax][Message][Error][NoUpdate2]','update','then','[Fax][Message][Updated]','[Fax][Message][NoUpdate1]','[Fax][Message][NoUpdate2]','\x20hangup\x20sendFile\x20','\x20hangup\x20faxRiceive\x20','faxpages','SUCCESS','updateStatus','faxstatusstring','SENDING\x20FAILED:\x20','execOriginate','FaxAccountId','[Fax][execOriginate][success]','message','Fax\x20received','[Fax][execOriginate][failure]','Fax\x20failed','checkAfterSend','checkTrunk','Trunk','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','execute','%s/%s.tif','dir','variablesAction','Action','addVariables','ext','.pdf','isTrunkReachable','isNil','active','SIP/%s','reachable','unmonitored','[Fax][checkTrunk][Trunk\x20not\x20working\x20correctly]','Trunk\x20not\x20working\x20correctly','[Fax][checkTrunk][Empty\x20Fax]','Empty\x20Fax','Is\x20Valid','exports','util','lodash','bluebird','uuid','moment','path','tiff2pdf','./util/gs','../../../config/logger','fax','./rpcDb','./channel','./util/util','./action','../rpc/faxAccount','../rpc/attachment','../rpc/faxMessage','channels','faxAccounts','trunks','actions','syncNewchannel','bind','varset','syncVarSet','syncNewState','newexten','syncNewExten','faxstatus','syncFaxStatus','receivefax','syncReceiveFax','syncHangup','originateresponse','syncOriginateResponse','prototype','context','from-voip-provider','exten','localstationid','uniqueid','channel','name','info','\x20syncNewchannel\x20','variable','value','channelstatedesc','hasOwnProperty','operation','status','filename','\x20syncFaxStatus\x20','remotestationid','pagestransferred','resolution','transferrate','calleridnum','/var/opt/motion2/server/files/attachments/','\x20result\x20conversion\x20file\x20','parse','application/pdf','notify','catch','stringify','\x20receiveFax\x20','merge','response','reason','AttachmentId'];(function(_0x5b5eb4,_0x117c87){var _0x42af53=function(_0xdf6fcb){while(--_0xdf6fcb){_0x5b5eb4['push'](_0x5b5eb4['shift']());}};_0x42af53(++_0x117c87);}(_0xa0f2,0x19a));var _0x2a0f=function(_0x41053d,_0x2a4167){_0x41053d=_0x41053d-0x0;var _0x403026=_0xa0f2[_0x41053d];return _0x403026;};'use strict';var util=require(_0x2a0f('0x0'));var _=require(_0x2a0f('0x1'));var BPromise=require(_0x2a0f('0x2'));var uuid=require(_0x2a0f('0x3'));var moment=require(_0x2a0f('0x4'));var path=require(_0x2a0f('0x5'));var tiff2pdf=require(_0x2a0f('0x6'));var gs=require(_0x2a0f('0x7'));var logger=require(_0x2a0f('0x8'))(_0x2a0f('0x9'));var ami=require('../ami');var rpcDb=require(_0x2a0f('0xa'));var Channel=require(_0x2a0f('0xb'));var ut=require(_0x2a0f('0xc'));var Action=require(_0x2a0f('0xd'));var faxAccount=require(_0x2a0f('0xe'));var attachment=require(_0x2a0f('0xf'));var faxMessage=require(_0x2a0f('0x10'));function Fax(_0x1571b6){this[_0x2a0f('0x11')]={};this[_0x2a0f('0x12')]=_0x1571b6[_0x2a0f('0x12')];this[_0x2a0f('0x13')]=_0x1571b6[_0x2a0f('0x13')];this[_0x2a0f('0x14')]={};ami['on']('newchannel',this[_0x2a0f('0x15')][_0x2a0f('0x16')](this));ami['on'](_0x2a0f('0x17'),this[_0x2a0f('0x18')][_0x2a0f('0x16')](this));ami['on']('newstate',this[_0x2a0f('0x19')][_0x2a0f('0x16')](this));ami['on'](_0x2a0f('0x1a'),this[_0x2a0f('0x1b')]['bind'](this));ami['on'](_0x2a0f('0x1c'),this[_0x2a0f('0x1d')][_0x2a0f('0x16')](this));ami['on'](_0x2a0f('0x1e'),this[_0x2a0f('0x1f')]['bind'](this));ami['on']('hangup',this[_0x2a0f('0x20')][_0x2a0f('0x16')](this));ami['on'](_0x2a0f('0x21'),this[_0x2a0f('0x22')][_0x2a0f('0x16')](this));}Fax[_0x2a0f('0x23')][_0x2a0f('0x15')]=function(_0x36d6e5){if(_0x36d6e5[_0x2a0f('0x24')]===_0x2a0f('0x25')){for(var _0x1f972c in this['faxAccounts']){if(this[_0x2a0f('0x12')]['hasOwnProperty'](_0x1f972c)){if(_0x36d6e5[_0x2a0f('0x26')]===this[_0x2a0f('0x12')][_0x1f972c][_0x2a0f('0x27')]){this[_0x2a0f('0x11')][_0x36d6e5['uniqueid']]={};this[_0x2a0f('0x11')][_0x36d6e5[_0x2a0f('0x28')]][_0x2a0f('0x29')]=_0x36d6e5['channel'];this[_0x2a0f('0x11')][_0x36d6e5['uniqueid']]['id']=this[_0x2a0f('0x12')][_0x1f972c]['id'];this[_0x2a0f('0x11')][_0x36d6e5[_0x2a0f('0x28')]][_0x2a0f('0x2a')]=this['faxAccounts'][_0x1f972c][_0x2a0f('0x2a')];logger[_0x2a0f('0x2b')](_0x36d6e5[_0x2a0f('0x28')],_0x2a0f('0x2c'));}}}}if(this[_0x2a0f('0x14')][_0x36d6e5[_0x2a0f('0x28')]]){this[_0x2a0f('0x11')][_0x36d6e5[_0x2a0f('0x28')]]={};this[_0x2a0f('0x11')][_0x36d6e5[_0x2a0f('0x28')]][_0x2a0f('0x29')]=_0x36d6e5['channel'];logger[_0x2a0f('0x2b')](_0x36d6e5[_0x2a0f('0x28')],_0x2a0f('0x2c'));}};Fax[_0x2a0f('0x23')][_0x2a0f('0x18')]=function(_0x1e706b){if(this[_0x2a0f('0x11')][_0x1e706b[_0x2a0f('0x28')]]){for(var _0x3fa6c8 in _0x1e706b[_0x2a0f('0x2d')]){if(_0x1e706b[_0x2a0f('0x2d')]['hasOwnProperty'](_0x3fa6c8)){this[_0x2a0f('0x11')][_0x1e706b[_0x2a0f('0x28')]][_0x3fa6c8]=_0x1e706b[_0x2a0f('0x2e')];}}}};Fax[_0x2a0f('0x23')][_0x2a0f('0x19')]=function(_0x17ec5d){if(this[_0x2a0f('0x11')][_0x17ec5d[_0x2a0f('0x28')]]){this[_0x2a0f('0x11')][_0x17ec5d[_0x2a0f('0x28')]]['channelstate']=_0x17ec5d['channelstate'];this[_0x2a0f('0x11')][_0x17ec5d[_0x2a0f('0x28')]][_0x2a0f('0x2f')]=_0x17ec5d['channelstatedesc'];}};Fax[_0x2a0f('0x23')][_0x2a0f('0x1b')]=function(_0x213786){if(this[_0x2a0f('0x11')][_0x213786[_0x2a0f('0x28')]]){for(var _0x3c7c20 in _0x213786[_0x2a0f('0x2d')]){if(_0x213786['variable'][_0x2a0f('0x30')](_0x3c7c20)){this[_0x2a0f('0x11')][_0x213786['uniqueid']][_0x3c7c20]=_0x213786[_0x2a0f('0x2e')];}}}};Fax[_0x2a0f('0x23')]['syncFaxStatus']=function(_0x31bfc9){if(this[_0x2a0f('0x11')][_0x31bfc9['uniqueid']]){this[_0x2a0f('0x11')][_0x31bfc9[_0x2a0f('0x28')]][_0x2a0f('0x31')]=_0x31bfc9[_0x2a0f('0x31')];this[_0x2a0f('0x11')][_0x31bfc9[_0x2a0f('0x28')]][_0x2a0f('0x32')]=_0x31bfc9['status'];this[_0x2a0f('0x11')][_0x31bfc9[_0x2a0f('0x28')]]['localstationid']=_0x31bfc9[_0x2a0f('0x27')];this[_0x2a0f('0x11')][_0x31bfc9[_0x2a0f('0x28')]][_0x2a0f('0x33')]=_0x31bfc9[_0x2a0f('0x33')];logger[_0x2a0f('0x2b')](_0x31bfc9[_0x2a0f('0x28')],_0x2a0f('0x34'));}};Fax['prototype'][_0x2a0f('0x1f')]=function(_0x45cf9c){var _0x52c98e=this;if(this[_0x2a0f('0x11')][_0x45cf9c[_0x2a0f('0x28')]]){var _0x3889ce=this[_0x2a0f('0x11')][_0x45cf9c[_0x2a0f('0x28')]]['id'];this[_0x2a0f('0x11')][_0x45cf9c['uniqueid']][_0x2a0f('0x35')]=_0x45cf9c[_0x2a0f('0x35')];this[_0x2a0f('0x11')][_0x45cf9c[_0x2a0f('0x28')]][_0x2a0f('0x36')]=_0x45cf9c['pagestransferred'];this[_0x2a0f('0x11')][_0x45cf9c[_0x2a0f('0x28')]][_0x2a0f('0x27')]=_0x45cf9c[_0x2a0f('0x27')];this['channels'][_0x45cf9c[_0x2a0f('0x28')]][_0x2a0f('0x37')]=_0x45cf9c[_0x2a0f('0x37')];this['channels'][_0x45cf9c[_0x2a0f('0x28')]][_0x2a0f('0x38')]=_0x45cf9c[_0x2a0f('0x38')];this[_0x2a0f('0x11')][_0x45cf9c['uniqueid']]['filename']=_0x45cf9c[_0x2a0f('0x33')];this[_0x2a0f('0x11')][_0x45cf9c[_0x2a0f('0x28')]]['calleridnum']=_0x45cf9c[_0x2a0f('0x39')];if(this[_0x2a0f('0x11')][_0x45cf9c[_0x2a0f('0x28')]]['pagestransferred']>0x0){tiff2pdf(_0x45cf9c['filename'],_0x2a0f('0x3a'),function(_0x8f3330){logger['info'](_0x45cf9c[_0x2a0f('0x28')],_0x2a0f('0x3b'),_0x8f3330['message']);attachment['create']({'name':path[_0x2a0f('0x3c')](_0x45cf9c[_0x2a0f('0x33')])[_0x2a0f('0x2a')],'basename':path[_0x2a0f('0x3c')](_0x45cf9c[_0x2a0f('0x33')])['name']+'.pdf','type':_0x2a0f('0x3d')})['then'](function(_0x243fcc){faxAccount[_0x2a0f('0x3e')](_0x3889ce,{'from':_0x45cf9c[_0x2a0f('0x39')],'mapKey':_0x2a0f('0x9'),'body':path[_0x2a0f('0x3c')](_0x45cf9c[_0x2a0f('0x33')])[_0x2a0f('0x2a')]+'.pdf','AttachmentId':_0x243fcc['id']})[_0x2a0f('0x3f')](function(_0x37d059){logger['error'](_0x45cf9c[_0x2a0f('0x28')],'\x20notify\x20',JSON[_0x2a0f('0x40')](_0x37d059));});})[_0x2a0f('0x3f')](function(_0x30d8f4){logger['error'](_0x45cf9c[_0x2a0f('0x28')],_0x2a0f('0x41'),JSON[_0x2a0f('0x40')](_0x30d8f4));});});}logger['info'](_0x45cf9c[_0x2a0f('0x28')],'\x20receiveFax\x20');}};Fax[_0x2a0f('0x23')][_0x2a0f('0x22')]=function(_0x3eb49c){if(this[_0x2a0f('0x14')][_0x3eb49c['uniqueid']]){_[_0x2a0f('0x42')](this[_0x2a0f('0x11')][_0x3eb49c['uniqueid']],_['pick'](_0x3eb49c,[_0x2a0f('0x43'),_0x2a0f('0x44')]));}};function updateStatus(_0x26fa88){if(_0x26fa88[_0x2a0f('0x45')]){faxMessage['update'](_0x26fa88[_0x2a0f('0x45')],{'failMessage':_0x2a0f('0x46')})['then'](function(_0x5b0cce){ut['logger'](_0x2a0f('0x47'),_0x5b0cce);})['catch'](function(_0x5d3c98){ut[_0x2a0f('0x48')]('[Fax][Message][Error][NoUpdate1]',_0x5d3c98);});}else{ut[_0x2a0f('0x48')](_0x2a0f('0x49'));}}Fax[_0x2a0f('0x23')]['updateStatus']=function(_0x4c0fbf,_0x53a553,_0x55bf00){var _0x53bc2e=this;var _0x4662c9={};if(_0x53a553){_0x4662c9={'read':_0x53a553};}else{_0x4662c9={'failMessage':_0x55bf00};}if(this['actions'][_0x4c0fbf][_0x2a0f('0x45')]){faxMessage[_0x2a0f('0x4a')](this[_0x2a0f('0x14')][_0x4c0fbf]['AttachmentId'],_0x4662c9)[_0x2a0f('0x4b')](function(_0x4c7af6){ut[_0x2a0f('0x48')](_0x2a0f('0x4c'),_0x4c7af6);})[_0x2a0f('0x3f')](function(_0x3dca1c){ut[_0x2a0f('0x48')](_0x2a0f('0x4d'),_0x3dca1c);})['finally'](function(){delete _0x53bc2e[_0x2a0f('0x11')][_0x4c0fbf];delete _0x53bc2e[_0x2a0f('0x14')][_0x4c0fbf];});}else{ut[_0x2a0f('0x48')](_0x2a0f('0x4e'));delete this[_0x2a0f('0x11')][_0x4c0fbf];delete this[_0x2a0f('0x14')][_0x4c0fbf];}};Fax[_0x2a0f('0x23')][_0x2a0f('0x20')]=function(_0x27fdaa){var _0x42d4ce=this;if(this[_0x2a0f('0x11')][_0x27fdaa[_0x2a0f('0x28')]]){if(this[_0x2a0f('0x14')][_0x27fdaa['uniqueid']]){this[_0x2a0f('0x11')][_0x27fdaa[_0x2a0f('0x28')]]['id']=this[_0x2a0f('0x14')][_0x27fdaa[_0x2a0f('0x28')]]['id'];this[_0x2a0f('0x11')][_0x27fdaa[_0x2a0f('0x28')]][_0x2a0f('0x2a')]=this['actions'][_0x27fdaa[_0x2a0f('0x28')]][_0x2a0f('0x2a')];}logger[_0x2a0f('0x2b')](_0x27fdaa['uniqueid'],this[_0x2a0f('0x14')][_0x27fdaa[_0x2a0f('0x28')]]?_0x2a0f('0x4f'):_0x2a0f('0x50'),JSON[_0x2a0f('0x40')](this[_0x2a0f('0x11')][_0x27fdaa[_0x2a0f('0x28')]]));if(this[_0x2a0f('0x14')][_0x27fdaa[_0x2a0f('0x28')]]){if(this['channels'][_0x27fdaa['uniqueid']][_0x2a0f('0x51')]>0x0&&this['channels'][_0x27fdaa[_0x2a0f('0x28')]]['faxstatus']===_0x2a0f('0x52')){this[_0x2a0f('0x53')](_0x27fdaa['uniqueid'],!![]);}else{this[_0x2a0f('0x53')](_0x27fdaa[_0x2a0f('0x28')],![],this[_0x2a0f('0x11')][_0x27fdaa[_0x2a0f('0x28')]][_0x2a0f('0x54')]?_0x2a0f('0x55')+this[_0x2a0f('0x11')][_0x27fdaa[_0x2a0f('0x28')]][_0x2a0f('0x54')]:'SENDING\x20FAILED');}}}};Fax['prototype']['send']=function(_0x3edfe9){var _0xb4e3c2=this;return new BPromise(function(_0x13b103,_0x36e0bf){_0xb4e3c2[_0x2a0f('0x56')](_0x3edfe9,_0xb4e3c2[_0x2a0f('0x12')][_0x3edfe9[_0x2a0f('0x57')]])[_0x2a0f('0x4b')](function(_0x1b3665){ut[_0x2a0f('0x48')](_0x2a0f('0x58'),_0x1b3665);_0x13b103(ut[_0x2a0f('0x59')](_0x2a0f('0x5a')));})['catch'](function(_0x50ba4b){ut['logger'](_0x2a0f('0x5b'),_0x50ba4b);updateStatus(_0x3edfe9);_0x36e0bf(ut[_0x2a0f('0x59')](_0x2a0f('0x5c')));});});};Fax[_0x2a0f('0x23')][_0x2a0f('0x5d')]=function(_0x1e7c34){var _0x5a4a75=this;return new BPromise(function(_0x408489,_0x1d19d9){var _0xb37794=_0x5a4a75[_0x2a0f('0x5e')](_0x5a4a75['faxAccounts'][_0x1e7c34[_0x2a0f('0x57')]][_0x2a0f('0x5f')],_0x1e7c34);if(_0xb37794[_0x2a0f('0x60')]){_0x408489(ut[_0x2a0f('0x59')](_0x2a0f('0x61')));}else{_0x1d19d9(ut['message'](_0xb37794[_0x2a0f('0x59')]));}});};function originate(_0x4860c9,_0x2f0f0a,_0x252875){return new BPromise(function(_0x31fdb4,_0x136449){if(_0x252875){var _0x6c027f=util[_0x2a0f('0x62')](_0x2a0f('0x63'),path[_0x2a0f('0x3c')](_0x4860c9[_0x2a0f('0x5')])['name'],_0x4860c9[_0x2a0f('0x5')]);gs[_0x2a0f('0x64')](_0x6c027f)[_0x2a0f('0x4b')](function(){_0x4860c9['path']=util[_0x2a0f('0x62')](_0x2a0f('0x65'),path[_0x2a0f('0x3c')](_0x4860c9[_0x2a0f('0x5')])[_0x2a0f('0x66')],path[_0x2a0f('0x3c')](_0x4860c9[_0x2a0f('0x5')])[_0x2a0f('0x2a')]);_0x2f0f0a['XMF-PATH']=_0x4860c9['path'];ut[_0x2a0f('0x48')]('Convert\x20pdf\x20to\x20tif','');ami['Action'](ut[_0x2a0f('0x67')](_0x4860c9,_0x2f0f0a))[_0x2a0f('0x4b')](function(_0x48c20a){_0x31fdb4(_0x48c20a);})[_0x2a0f('0x3f')](function(_0x4d3e53){_0x136449(_0x4d3e53);});})[_0x2a0f('0x3f')](function(_0x823d72){_0x136449(_0x823d72);});}else{ami[_0x2a0f('0x68')](ut['variablesAction'](_0x4860c9,_0x2f0f0a))[_0x2a0f('0x4b')](function(_0x4bae97){_0x31fdb4(_0x4bae97);})[_0x2a0f('0x3f')](function(_0x11b8ef){_0x136449(_0x11b8ef);});}});}Fax[_0x2a0f('0x23')][_0x2a0f('0x56')]=function(_0x4f6b51,_0x4a5946){var _0xb56304=this;return new BPromise(function(_0x947eeb,_0x30817c){var _0x265c9e=uuid['v4']();var _0x59f949=ut[_0x2a0f('0x69')](_0x4f6b51,_0x4a5946);_0xb56304['actions'][_0x265c9e]=new Action(_0x265c9e,_0x4a5946,_0x4f6b51);var _0x3fc811=_0xb56304[_0x2a0f('0x14')][_0x265c9e];if(path[_0x2a0f('0x3c')](_0x4f6b51[_0x2a0f('0x5')])[_0x2a0f('0x6a')]===_0x2a0f('0x6b')){originate(_0x3fc811,_0x59f949,!![])[_0x2a0f('0x4b')](function(_0x31aa1e){_0x947eeb(_0x31aa1e);})[_0x2a0f('0x3f')](function(_0x3a1d91){_0x30817c(_0x3a1d91);});}else{originate(_0x3fc811,_0x59f949,![])[_0x2a0f('0x4b')](function(_0x899285){_0x947eeb(_0x899285);})[_0x2a0f('0x3f')](function(_0x42a536){_0x30817c(_0x42a536);});}});};Fax[_0x2a0f('0x23')][_0x2a0f('0x6c')]=function(_0x2d2121){return!_[_0x2a0f('0x6d')](_0x2d2121)&&!_[_0x2a0f('0x6d')](_0x2d2121[_0x2a0f('0x2a')])&&!_[_0x2a0f('0x6d')](_0x2d2121[_0x2a0f('0x6e')])&&_0x2d2121[_0x2a0f('0x6e')]&&!_[_0x2a0f('0x6d')](this[_0x2a0f('0x13')][util[_0x2a0f('0x62')](_0x2a0f('0x6f'),_0x2d2121[_0x2a0f('0x2a')])])&&!_[_0x2a0f('0x6d')](this[_0x2a0f('0x13')][util[_0x2a0f('0x62')](_0x2a0f('0x6f'),_0x2d2121[_0x2a0f('0x2a')])][_0x2a0f('0x32')])&&(this[_0x2a0f('0x13')][util[_0x2a0f('0x62')](_0x2a0f('0x6f'),_0x2d2121[_0x2a0f('0x2a')])][_0x2a0f('0x32')]===_0x2a0f('0x70')||this[_0x2a0f('0x13')][util['format'](_0x2a0f('0x6f'),_0x2d2121[_0x2a0f('0x2a')])]['status']===_0x2a0f('0x71'));};Fax['prototype'][_0x2a0f('0x5e')]=function(_0x57287f,_0x2af6bf){if(!this[_0x2a0f('0x6c')](_0x57287f)){ut[_0x2a0f('0x48')](_0x2a0f('0x72'),_[_0x2a0f('0x6d')](_0x57287f)?'':_0x57287f[_0x2a0f('0x2a')]+'\x20Trunk\x20is\x20not\x20active');return{'isValid':![],'message':_0x2a0f('0x73')};}if(_['isNil'](_0x2af6bf[_0x2a0f('0x9')])){ut[_0x2a0f('0x48')](_0x2a0f('0x74'),JSON[_0x2a0f('0x40')](_0x2af6bf));return{'isValid':![],'message':_0x2a0f('0x75')};}if(_['isNil'](_0x2af6bf[_0x2a0f('0x5')])){ut[_0x2a0f('0x48')]('[Fax][checkTrunk][Empty\x20path]',JSON[_0x2a0f('0x40')](_0x2af6bf));return{'isValid':![],'message':'Empty\x20path'};}return{'isValid':!![],'message':_0x2a0f('0x76')};};module[_0x2a0f('0x77')]=Fax;
\ No newline at end of file