Built motion from commit 37e1ed56.|2.6.29
[motion2.git] / server / services / ami / fax / index.js
index 1bf6a92..14c24ab 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x57a0=['isNil','SIP/%s','[Fax][checkTrunk][Trunk\x20not\x20working\x20correctly]','\x20Trunk\x20is\x20not\x20active','Trunk\x20not\x20working\x20correctly','[Fax][checkTrunk][Empty\x20Fax]','[Fax][checkTrunk][Empty\x20path]','Empty\x20path','Is\x20Valid','exports','util','bluebird','uuid','path','tiff2pdf','./util/gs','../../../config/logger','../ami','./rpcDb','./util/util','./action','../rpc/faxAccount','../rpc/attachment','../rpc/faxMessage','channels','faxAccounts','trunks','actions','newchannel','syncNewchannel','bind','varset','syncVarSet','newstate','syncNewState','syncNewExten','faxstatus','receivefax','syncReceiveFax','hangup','syncHangup','syncOriginateResponse','prototype','context','hasOwnProperty','exten','localstationid','uniqueid','channel','name','\x20syncNewchannel\x20','info','variable','channelstate','channelstatedesc','value','syncFaxStatus','operation','status','filename','remotestationid','pagestransferred','resolution','calleridnum','/var/opt/motion2/server/files/attachments/','\x20result\x20conversion\x20file\x20','message','create','parse','.pdf','application/pdf','fax','error','stringify','catch','\x20receiveFax\x20','merge','response','reason','AttachmentId','update','then','logger','[Fax][Message][Error][Updated]','[Fax][Message][Error][NoUpdate1]','[Fax][Message][Error][NoUpdate2]','[Fax][Message][NoUpdate1]','finally','[Fax][Message][NoUpdate2]','faxpages','updateStatus','SENDING\x20FAILED:\x20','SENDING\x20FAILED','send','execOriginate','FaxAccountId','Fax\x20received','[Fax][execOriginate][failure]','checkAfterSend','checkTrunk','Trunk','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','XMF-PATH','Convert\x20pdf\x20to\x20tif','Action','variablesAction','addVariables','isTrunkReachable'];(function(_0x4702ee,_0xaf6a45){var _0x62ca7d=function(_0x5b3af7){while(--_0x5b3af7){_0x4702ee['push'](_0x4702ee['shift']());}};_0x62ca7d(++_0xaf6a45);}(_0x57a0,0x7b));var _0x057a=function(_0x4b3dba,_0x562c7d){_0x4b3dba=_0x4b3dba-0x0;var _0x2f6480=_0x57a0[_0x4b3dba];return _0x2f6480;};'use strict';var util=require(_0x057a('0x0'));var _=require('lodash');var BPromise=require(_0x057a('0x1'));var uuid=require(_0x057a('0x2'));var moment=require('moment');var path=require(_0x057a('0x3'));var tiff2pdf=require(_0x057a('0x4'));var gs=require(_0x057a('0x5'));var logger=require(_0x057a('0x6'))('fax');var ami=require(_0x057a('0x7'));var rpcDb=require(_0x057a('0x8'));var Channel=require('./channel');var ut=require(_0x057a('0x9'));var Action=require(_0x057a('0xa'));var faxAccount=require(_0x057a('0xb'));var attachment=require(_0x057a('0xc'));var faxMessage=require(_0x057a('0xd'));function Fax(_0x322d14){this[_0x057a('0xe')]={};this[_0x057a('0xf')]=_0x322d14[_0x057a('0xf')];this['trunks']=_0x322d14[_0x057a('0x10')];this[_0x057a('0x11')]={};ami['on'](_0x057a('0x12'),this[_0x057a('0x13')][_0x057a('0x14')](this));ami['on'](_0x057a('0x15'),this[_0x057a('0x16')]['bind'](this));ami['on'](_0x057a('0x17'),this[_0x057a('0x18')][_0x057a('0x14')](this));ami['on']('newexten',this[_0x057a('0x19')][_0x057a('0x14')](this));ami['on'](_0x057a('0x1a'),this['syncFaxStatus'][_0x057a('0x14')](this));ami['on'](_0x057a('0x1b'),this[_0x057a('0x1c')][_0x057a('0x14')](this));ami['on'](_0x057a('0x1d'),this[_0x057a('0x1e')][_0x057a('0x14')](this));ami['on']('originateresponse',this[_0x057a('0x1f')][_0x057a('0x14')](this));}Fax[_0x057a('0x20')][_0x057a('0x13')]=function(_0x495335){if(_0x495335[_0x057a('0x21')]==='from-voip-provider'){for(var _0x2b90eb in this[_0x057a('0xf')]){if(this[_0x057a('0xf')][_0x057a('0x22')](_0x2b90eb)){if(_0x495335[_0x057a('0x23')]===this[_0x057a('0xf')][_0x2b90eb][_0x057a('0x24')]){this[_0x057a('0xe')][_0x495335[_0x057a('0x25')]]={};this[_0x057a('0xe')][_0x495335[_0x057a('0x25')]][_0x057a('0x26')]=_0x495335[_0x057a('0x26')];this[_0x057a('0xe')][_0x495335[_0x057a('0x25')]]['id']=this[_0x057a('0xf')][_0x2b90eb]['id'];this[_0x057a('0xe')][_0x495335['uniqueid']][_0x057a('0x27')]=this[_0x057a('0xf')][_0x2b90eb][_0x057a('0x27')];logger['info'](_0x495335[_0x057a('0x25')],_0x057a('0x28'));}}}}if(this[_0x057a('0x11')][_0x495335[_0x057a('0x25')]]){this[_0x057a('0xe')][_0x495335[_0x057a('0x25')]]={};this['channels'][_0x495335[_0x057a('0x25')]][_0x057a('0x26')]=_0x495335[_0x057a('0x26')];logger[_0x057a('0x29')](_0x495335[_0x057a('0x25')],'\x20syncNewchannel\x20');}};Fax['prototype'][_0x057a('0x16')]=function(_0x4d0741){if(this[_0x057a('0xe')][_0x4d0741[_0x057a('0x25')]]){for(var _0x3390ed in _0x4d0741[_0x057a('0x2a')]){if(_0x4d0741[_0x057a('0x2a')][_0x057a('0x22')](_0x3390ed)){this[_0x057a('0xe')][_0x4d0741[_0x057a('0x25')]][_0x3390ed]=_0x4d0741['value'];}}}};Fax[_0x057a('0x20')][_0x057a('0x18')]=function(_0x3253bf){if(this[_0x057a('0xe')][_0x3253bf[_0x057a('0x25')]]){this[_0x057a('0xe')][_0x3253bf[_0x057a('0x25')]][_0x057a('0x2b')]=_0x3253bf[_0x057a('0x2b')];this[_0x057a('0xe')][_0x3253bf[_0x057a('0x25')]][_0x057a('0x2c')]=_0x3253bf[_0x057a('0x2c')];}};Fax[_0x057a('0x20')]['syncNewExten']=function(_0x3d5b97){if(this[_0x057a('0xe')][_0x3d5b97[_0x057a('0x25')]]){for(var _0x5e8876 in _0x3d5b97[_0x057a('0x2a')]){if(_0x3d5b97[_0x057a('0x2a')][_0x057a('0x22')](_0x5e8876)){this[_0x057a('0xe')][_0x3d5b97[_0x057a('0x25')]][_0x5e8876]=_0x3d5b97[_0x057a('0x2d')];}}}};Fax[_0x057a('0x20')][_0x057a('0x2e')]=function(_0x1daae3){if(this[_0x057a('0xe')][_0x1daae3[_0x057a('0x25')]]){this['channels'][_0x1daae3['uniqueid']][_0x057a('0x2f')]=_0x1daae3['operation'];this['channels'][_0x1daae3[_0x057a('0x25')]][_0x057a('0x30')]=_0x1daae3[_0x057a('0x30')];this[_0x057a('0xe')][_0x1daae3[_0x057a('0x25')]]['localstationid']=_0x1daae3[_0x057a('0x24')];this['channels'][_0x1daae3['uniqueid']][_0x057a('0x31')]=_0x1daae3[_0x057a('0x31')];logger[_0x057a('0x29')](_0x1daae3[_0x057a('0x25')],'\x20syncFaxStatus\x20');}};Fax['prototype'][_0x057a('0x1c')]=function(_0x1a5ce7){var _0x2e6445=this;if(this[_0x057a('0xe')][_0x1a5ce7[_0x057a('0x25')]]){var _0x12612a=this[_0x057a('0xe')][_0x1a5ce7['uniqueid']]['id'];this[_0x057a('0xe')][_0x1a5ce7['uniqueid']][_0x057a('0x32')]=_0x1a5ce7[_0x057a('0x32')];this[_0x057a('0xe')][_0x1a5ce7[_0x057a('0x25')]][_0x057a('0x33')]=_0x1a5ce7['pagestransferred'];this['channels'][_0x1a5ce7['uniqueid']][_0x057a('0x24')]=_0x1a5ce7['localstationid'];this['channels'][_0x1a5ce7[_0x057a('0x25')]][_0x057a('0x34')]=_0x1a5ce7[_0x057a('0x34')];this['channels'][_0x1a5ce7['uniqueid']]['transferrate']=_0x1a5ce7['transferrate'];this[_0x057a('0xe')][_0x1a5ce7[_0x057a('0x25')]]['filename']=_0x1a5ce7[_0x057a('0x31')];this[_0x057a('0xe')][_0x1a5ce7['uniqueid']][_0x057a('0x35')]=_0x1a5ce7[_0x057a('0x35')];if(this[_0x057a('0xe')][_0x1a5ce7[_0x057a('0x25')]][_0x057a('0x33')]>0x0){tiff2pdf(_0x1a5ce7[_0x057a('0x31')],_0x057a('0x36'),function(_0x2110f3){logger['info'](_0x1a5ce7[_0x057a('0x25')],_0x057a('0x37'),_0x2110f3[_0x057a('0x38')]);attachment[_0x057a('0x39')]({'name':path[_0x057a('0x3a')](_0x1a5ce7['filename'])['name'],'basename':path[_0x057a('0x3a')](_0x1a5ce7[_0x057a('0x31')])[_0x057a('0x27')]+_0x057a('0x3b'),'type':_0x057a('0x3c')})['then'](function(_0x13fe4e){faxAccount['notify'](_0x12612a,{'from':_0x1a5ce7[_0x057a('0x35')],'mapKey':_0x057a('0x3d'),'body':path[_0x057a('0x3a')](_0x1a5ce7[_0x057a('0x31')])['name']+_0x057a('0x3b'),'AttachmentId':_0x13fe4e['id']})['catch'](function(_0x39a208){logger[_0x057a('0x3e')](_0x1a5ce7[_0x057a('0x25')],'\x20notify\x20',JSON[_0x057a('0x3f')](_0x39a208));});})[_0x057a('0x40')](function(_0x28e680){logger['error'](_0x1a5ce7[_0x057a('0x25')],'\x20receiveFax\x20',JSON[_0x057a('0x3f')](_0x28e680));});});}logger[_0x057a('0x29')](_0x1a5ce7['uniqueid'],_0x057a('0x41'));}};Fax[_0x057a('0x20')][_0x057a('0x1f')]=function(_0x321d81){if(this[_0x057a('0x11')][_0x321d81['uniqueid']]){_[_0x057a('0x42')](this[_0x057a('0xe')][_0x321d81[_0x057a('0x25')]],_['pick'](_0x321d81,[_0x057a('0x43'),_0x057a('0x44')]));}};function updateStatus(_0x1124b8){if(_0x1124b8[_0x057a('0x45')]){faxMessage[_0x057a('0x46')](_0x1124b8['AttachmentId'],{'failMessage':'SENDING\x20FAILED\x20'})[_0x057a('0x47')](function(_0x5a8c2c){ut[_0x057a('0x48')](_0x057a('0x49'),_0x5a8c2c);})['catch'](function(_0x24b7ff){ut[_0x057a('0x48')](_0x057a('0x4a'),_0x24b7ff);});}else{ut[_0x057a('0x48')](_0x057a('0x4b'));}}Fax['prototype']['updateStatus']=function(_0x2d57ee,_0x477c59,_0x8c66f8){var _0x49674f=this;var _0x16f6b8={};if(_0x477c59){_0x16f6b8={'read':_0x477c59};}else{_0x16f6b8={'failMessage':_0x8c66f8};}if(this[_0x057a('0x11')][_0x2d57ee][_0x057a('0x45')]){faxMessage[_0x057a('0x46')](this[_0x057a('0x11')][_0x2d57ee][_0x057a('0x45')],_0x16f6b8)['then'](function(_0x486ae2){ut['logger']('[Fax][Message][Updated]',_0x486ae2);})[_0x057a('0x40')](function(_0x5691ea){ut[_0x057a('0x48')](_0x057a('0x4c'),_0x5691ea);})[_0x057a('0x4d')](function(){delete _0x49674f[_0x057a('0xe')][_0x2d57ee];delete _0x49674f['actions'][_0x2d57ee];});}else{ut[_0x057a('0x48')](_0x057a('0x4e'));delete this[_0x057a('0xe')][_0x2d57ee];delete this[_0x057a('0x11')][_0x2d57ee];}};Fax[_0x057a('0x20')][_0x057a('0x1e')]=function(_0xa72a9b){var _0x358dba=this;if(this[_0x057a('0xe')][_0xa72a9b[_0x057a('0x25')]]){if(this['actions'][_0xa72a9b[_0x057a('0x25')]]){this[_0x057a('0xe')][_0xa72a9b[_0x057a('0x25')]]['id']=this['actions'][_0xa72a9b[_0x057a('0x25')]]['id'];this[_0x057a('0xe')][_0xa72a9b[_0x057a('0x25')]][_0x057a('0x27')]=this[_0x057a('0x11')][_0xa72a9b[_0x057a('0x25')]][_0x057a('0x27')];}logger[_0x057a('0x29')](_0xa72a9b['uniqueid'],this['actions'][_0xa72a9b[_0x057a('0x25')]]?'\x20hangup\x20sendFile\x20':'\x20hangup\x20faxRiceive\x20',JSON[_0x057a('0x3f')](this['channels'][_0xa72a9b['uniqueid']]));if(this[_0x057a('0x11')][_0xa72a9b['uniqueid']]){if(this[_0x057a('0xe')][_0xa72a9b[_0x057a('0x25')]][_0x057a('0x4f')]>0x0&&this[_0x057a('0xe')][_0xa72a9b['uniqueid']][_0x057a('0x1a')]==='SUCCESS'){this[_0x057a('0x50')](_0xa72a9b[_0x057a('0x25')],!![]);}else{this[_0x057a('0x50')](_0xa72a9b[_0x057a('0x25')],![],this['channels'][_0xa72a9b[_0x057a('0x25')]]['faxstatusstring']?_0x057a('0x51')+this[_0x057a('0xe')][_0xa72a9b[_0x057a('0x25')]]['faxstatusstring']:_0x057a('0x52'));}}}};Fax[_0x057a('0x20')][_0x057a('0x53')]=function(_0x3c1126){var _0x301d6f=this;return new BPromise(function(_0x4935bc,_0x5b9fe4){_0x301d6f[_0x057a('0x54')](_0x3c1126,_0x301d6f[_0x057a('0xf')][_0x3c1126[_0x057a('0x55')]])[_0x057a('0x47')](function(_0x323f74){ut[_0x057a('0x48')]('[Fax][execOriginate][success]',_0x323f74);_0x4935bc(ut[_0x057a('0x38')](_0x057a('0x56')));})[_0x057a('0x40')](function(_0x4e11fb){ut['logger'](_0x057a('0x57'),_0x4e11fb);updateStatus(_0x3c1126);_0x5b9fe4(ut[_0x057a('0x38')]('Fax\x20failed'));});});};Fax[_0x057a('0x20')][_0x057a('0x58')]=function(_0x422c7f){var _0x3850a6=this;return new BPromise(function(_0x3a3658,_0x165549){var _0x143f83=_0x3850a6[_0x057a('0x59')](_0x3850a6[_0x057a('0xf')][_0x422c7f['FaxAccountId']][_0x057a('0x5a')],_0x422c7f);if(_0x143f83['isValid']){_0x3a3658(ut[_0x057a('0x38')](_0x057a('0x5b')));}else{_0x165549(ut[_0x057a('0x38')](_0x143f83[_0x057a('0x38')]));}});};function originate(_0x3305ca,_0x5bdc41,_0x3897c9){return new BPromise(function(_0x516833,_0x574609){if(_0x3897c9){var _0x1b875e=util[_0x057a('0x5c')](_0x057a('0x5d'),path['parse'](_0x3305ca[_0x057a('0x3')])[_0x057a('0x27')],_0x3305ca[_0x057a('0x3')]);gs[_0x057a('0x5e')](_0x1b875e)['then'](function(){_0x3305ca['path']=util[_0x057a('0x5c')](_0x057a('0x5f'),path[_0x057a('0x3a')](_0x3305ca[_0x057a('0x3')])[_0x057a('0x60')],path[_0x057a('0x3a')](_0x3305ca[_0x057a('0x3')])[_0x057a('0x27')]);_0x5bdc41[_0x057a('0x61')]=_0x3305ca[_0x057a('0x3')];ut['logger'](_0x057a('0x62'),'');ami[_0x057a('0x63')](ut[_0x057a('0x64')](_0x3305ca,_0x5bdc41))[_0x057a('0x47')](function(_0x303586){_0x516833(_0x303586);})['catch'](function(_0x13e3d2){_0x574609(_0x13e3d2);});})[_0x057a('0x40')](function(_0x469c6f){_0x574609(_0x469c6f);});}else{ami[_0x057a('0x63')](ut['variablesAction'](_0x3305ca,_0x5bdc41))[_0x057a('0x47')](function(_0x42ce2a){_0x516833(_0x42ce2a);})['catch'](function(_0x8e2eb6){_0x574609(_0x8e2eb6);});}});}Fax[_0x057a('0x20')]['execOriginate']=function(_0x55a0a6,_0x2781ad){var _0x146b4b=this;return new BPromise(function(_0x43cb7c,_0x41156a){var _0x3b915b=uuid['v4']();var _0xaf220f=ut[_0x057a('0x65')](_0x55a0a6,_0x2781ad);_0x146b4b[_0x057a('0x11')][_0x3b915b]=new Action(_0x3b915b,_0x2781ad,_0x55a0a6);var _0x2d4ea1=_0x146b4b[_0x057a('0x11')][_0x3b915b];if(path[_0x057a('0x3a')](_0x55a0a6[_0x057a('0x3')])['ext']===_0x057a('0x3b')){originate(_0x2d4ea1,_0xaf220f,!![])['then'](function(_0x2ee32f){_0x43cb7c(_0x2ee32f);})[_0x057a('0x40')](function(_0x5d8e2e){_0x41156a(_0x5d8e2e);});}else{originate(_0x2d4ea1,_0xaf220f,![])[_0x057a('0x47')](function(_0x5018cd){_0x43cb7c(_0x5018cd);})[_0x057a('0x40')](function(_0x1e0020){_0x41156a(_0x1e0020);});}});};Fax[_0x057a('0x20')][_0x057a('0x66')]=function(_0x3a47bb){return!_[_0x057a('0x67')](_0x3a47bb)&&!_[_0x057a('0x67')](_0x3a47bb[_0x057a('0x27')])&&!_[_0x057a('0x67')](_0x3a47bb['active'])&&_0x3a47bb['active']&&!_['isNil'](this['trunks'][util['format']('SIP/%s',_0x3a47bb[_0x057a('0x27')])])&&!_[_0x057a('0x67')](this[_0x057a('0x10')][util[_0x057a('0x5c')](_0x057a('0x68'),_0x3a47bb[_0x057a('0x27')])][_0x057a('0x30')])&&(this['trunks'][util[_0x057a('0x5c')](_0x057a('0x68'),_0x3a47bb[_0x057a('0x27')])][_0x057a('0x30')]==='reachable'||this[_0x057a('0x10')][util[_0x057a('0x5c')]('SIP/%s',_0x3a47bb[_0x057a('0x27')])][_0x057a('0x30')]==='unmonitored');};Fax[_0x057a('0x20')][_0x057a('0x59')]=function(_0x34ac77,_0x492946){if(!this[_0x057a('0x66')](_0x34ac77)){ut['logger'](_0x057a('0x69'),_[_0x057a('0x67')](_0x34ac77)?'':_0x34ac77[_0x057a('0x27')]+_0x057a('0x6a'));return{'isValid':![],'message':_0x057a('0x6b')};}if(_['isNil'](_0x492946[_0x057a('0x3d')])){ut[_0x057a('0x48')](_0x057a('0x6c'),JSON[_0x057a('0x3f')](_0x492946));return{'isValid':![],'message':'Empty\x20Fax'};}if(_[_0x057a('0x67')](_0x492946[_0x057a('0x3')])){ut[_0x057a('0x48')](_0x057a('0x6d'),JSON[_0x057a('0x3f')](_0x492946));return{'isValid':![],'message':_0x057a('0x6e')};}return{'isValid':!![],'message':_0x057a('0x6f')};};module[_0x057a('0x70')]=Fax;
\ No newline at end of file
+var _0xa645=['execute','%s/%s.tif','dir','XMF-PATH','Convert\x20pdf\x20to\x20tif','Action','variablesAction','addVariables','ext','isTrunkReachable','isNil','active','SIP/%s','status','reachable','[Fax][checkTrunk][Trunk\x20not\x20working\x20correctly]','Trunk\x20not\x20working\x20correctly','[Fax][checkTrunk][Empty\x20Fax]','Empty\x20Fax','[Fax][checkTrunk][Empty\x20path]','Empty\x20path','Is\x20Valid','util','uuid','moment','tiff2pdf','./util/gs','../../../config/logger','../ami','./rpcDb','./channel','../rpc/faxAccount','../rpc/attachment','../rpc/faxMessage','channels','faxAccounts','trunks','syncNewchannel','varset','syncVarSet','bind','newstate','newexten','faxstatus','syncFaxStatus','receivefax','syncReceiveFax','hangup','syncHangup','originateresponse','syncOriginateResponse','prototype','context','from-voip-provider','hasOwnProperty','exten','uniqueid','channel','name','info','\x20syncNewchannel\x20','variable','value','syncNewState','channelstate','channelstatedesc','syncNewExten','operation','localstationid','filename','\x20syncFaxStatus\x20','remotestationid','pagestransferred','resolution','transferrate','calleridnum','/var/opt/motion2/server/files/attachments/','\x20result\x20conversion\x20file\x20','message','create','parse','.pdf','application/pdf','then','notify','fax','error','catch','\x20receiveFax\x20','stringify','actions','merge','pick','reason','AttachmentId','update','logger','[Fax][Message][Error][Updated]','[Fax][Message][Error][NoUpdate1]','[Fax][Message][Error][NoUpdate2]','updateStatus','[Fax][Message][NoUpdate1]','finally','\x20hangup\x20sendFile\x20','\x20hangup\x20faxRiceive\x20','faxpages','SUCCESS','faxstatusstring','SENDING\x20FAILED:\x20','SENDING\x20FAILED','send','execOriginate','FaxAccountId','[Fax][execOriginate][success]','Fax\x20received','[Fax][execOriginate][failure]','Fax\x20failed','checkAfterSend','checkTrunk','isValid','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'];(function(_0x5ce3c8,_0x2503bd){var _0xa76867=function(_0x52815e){while(--_0x52815e){_0x5ce3c8['push'](_0x5ce3c8['shift']());}};_0xa76867(++_0x2503bd);}(_0xa645,0x187));var _0x5a64=function(_0x4d1c50,_0x1c91ac){_0x4d1c50=_0x4d1c50-0x0;var _0x28ffc3=_0xa645[_0x4d1c50];return _0x28ffc3;};'use strict';var util=require(_0x5a64('0x0'));var _=require('lodash');var BPromise=require('bluebird');var uuid=require(_0x5a64('0x1'));var moment=require(_0x5a64('0x2'));var path=require('path');var tiff2pdf=require(_0x5a64('0x3'));var gs=require(_0x5a64('0x4'));var logger=require(_0x5a64('0x5'))('fax');var ami=require(_0x5a64('0x6'));var rpcDb=require(_0x5a64('0x7'));var Channel=require(_0x5a64('0x8'));var ut=require('./util/util');var Action=require('./action');var faxAccount=require(_0x5a64('0x9'));var attachment=require(_0x5a64('0xa'));var faxMessage=require(_0x5a64('0xb'));function Fax(_0x26abba){this[_0x5a64('0xc')]={};this[_0x5a64('0xd')]=_0x26abba[_0x5a64('0xd')];this[_0x5a64('0xe')]=_0x26abba[_0x5a64('0xe')];this['actions']={};ami['on']('newchannel',this[_0x5a64('0xf')]['bind'](this));ami['on'](_0x5a64('0x10'),this[_0x5a64('0x11')][_0x5a64('0x12')](this));ami['on'](_0x5a64('0x13'),this['syncNewState'][_0x5a64('0x12')](this));ami['on'](_0x5a64('0x14'),this['syncNewExten'][_0x5a64('0x12')](this));ami['on'](_0x5a64('0x15'),this[_0x5a64('0x16')]['bind'](this));ami['on'](_0x5a64('0x17'),this[_0x5a64('0x18')]['bind'](this));ami['on'](_0x5a64('0x19'),this[_0x5a64('0x1a')][_0x5a64('0x12')](this));ami['on'](_0x5a64('0x1b'),this[_0x5a64('0x1c')][_0x5a64('0x12')](this));}Fax[_0x5a64('0x1d')][_0x5a64('0xf')]=function(_0x1e93b9){if(_0x1e93b9[_0x5a64('0x1e')]===_0x5a64('0x1f')){for(var _0x247dfc in this[_0x5a64('0xd')]){if(this['faxAccounts'][_0x5a64('0x20')](_0x247dfc)){if(_0x1e93b9[_0x5a64('0x21')]===this[_0x5a64('0xd')][_0x247dfc]['localstationid']){this[_0x5a64('0xc')][_0x1e93b9[_0x5a64('0x22')]]={};this['channels'][_0x1e93b9[_0x5a64('0x22')]][_0x5a64('0x23')]=_0x1e93b9[_0x5a64('0x23')];this[_0x5a64('0xc')][_0x1e93b9[_0x5a64('0x22')]]['id']=this[_0x5a64('0xd')][_0x247dfc]['id'];this[_0x5a64('0xc')][_0x1e93b9[_0x5a64('0x22')]][_0x5a64('0x24')]=this[_0x5a64('0xd')][_0x247dfc]['name'];logger['info'](_0x1e93b9[_0x5a64('0x22')],'\x20syncNewchannel\x20');}}}}if(this['actions'][_0x1e93b9[_0x5a64('0x22')]]){this[_0x5a64('0xc')][_0x1e93b9[_0x5a64('0x22')]]={};this[_0x5a64('0xc')][_0x1e93b9[_0x5a64('0x22')]][_0x5a64('0x23')]=_0x1e93b9['channel'];logger[_0x5a64('0x25')](_0x1e93b9[_0x5a64('0x22')],_0x5a64('0x26'));}};Fax[_0x5a64('0x1d')]['syncVarSet']=function(_0x55af8d){if(this[_0x5a64('0xc')][_0x55af8d[_0x5a64('0x22')]]){for(var _0x1e22dc in _0x55af8d[_0x5a64('0x27')]){if(_0x55af8d[_0x5a64('0x27')]['hasOwnProperty'](_0x1e22dc)){this[_0x5a64('0xc')][_0x55af8d[_0x5a64('0x22')]][_0x1e22dc]=_0x55af8d[_0x5a64('0x28')];}}}};Fax[_0x5a64('0x1d')][_0x5a64('0x29')]=function(_0x3431b3){if(this['channels'][_0x3431b3[_0x5a64('0x22')]]){this[_0x5a64('0xc')][_0x3431b3[_0x5a64('0x22')]][_0x5a64('0x2a')]=_0x3431b3['channelstate'];this[_0x5a64('0xc')][_0x3431b3[_0x5a64('0x22')]][_0x5a64('0x2b')]=_0x3431b3[_0x5a64('0x2b')];}};Fax['prototype'][_0x5a64('0x2c')]=function(_0x5c9b3c){if(this['channels'][_0x5c9b3c[_0x5a64('0x22')]]){for(var _0x1e5488 in _0x5c9b3c['variable']){if(_0x5c9b3c['variable'][_0x5a64('0x20')](_0x1e5488)){this[_0x5a64('0xc')][_0x5c9b3c['uniqueid']][_0x1e5488]=_0x5c9b3c[_0x5a64('0x28')];}}}};Fax['prototype'][_0x5a64('0x16')]=function(_0xe5a9f7){if(this['channels'][_0xe5a9f7['uniqueid']]){this[_0x5a64('0xc')][_0xe5a9f7[_0x5a64('0x22')]]['operation']=_0xe5a9f7[_0x5a64('0x2d')];this[_0x5a64('0xc')][_0xe5a9f7[_0x5a64('0x22')]]['status']=_0xe5a9f7['status'];this[_0x5a64('0xc')][_0xe5a9f7[_0x5a64('0x22')]][_0x5a64('0x2e')]=_0xe5a9f7[_0x5a64('0x2e')];this[_0x5a64('0xc')][_0xe5a9f7['uniqueid']][_0x5a64('0x2f')]=_0xe5a9f7[_0x5a64('0x2f')];logger[_0x5a64('0x25')](_0xe5a9f7['uniqueid'],_0x5a64('0x30'));}};Fax[_0x5a64('0x1d')][_0x5a64('0x18')]=function(_0x3fcf3a){var _0x552017=this;if(this[_0x5a64('0xc')][_0x3fcf3a[_0x5a64('0x22')]]){var _0x956ac1=this['channels'][_0x3fcf3a[_0x5a64('0x22')]]['id'];this[_0x5a64('0xc')][_0x3fcf3a[_0x5a64('0x22')]][_0x5a64('0x31')]=_0x3fcf3a[_0x5a64('0x31')];this[_0x5a64('0xc')][_0x3fcf3a[_0x5a64('0x22')]][_0x5a64('0x32')]=_0x3fcf3a['pagestransferred'];this[_0x5a64('0xc')][_0x3fcf3a[_0x5a64('0x22')]][_0x5a64('0x2e')]=_0x3fcf3a[_0x5a64('0x2e')];this[_0x5a64('0xc')][_0x3fcf3a['uniqueid']][_0x5a64('0x33')]=_0x3fcf3a[_0x5a64('0x33')];this[_0x5a64('0xc')][_0x3fcf3a[_0x5a64('0x22')]][_0x5a64('0x34')]=_0x3fcf3a['transferrate'];this[_0x5a64('0xc')][_0x3fcf3a[_0x5a64('0x22')]][_0x5a64('0x2f')]=_0x3fcf3a['filename'];this[_0x5a64('0xc')][_0x3fcf3a['uniqueid']][_0x5a64('0x35')]=_0x3fcf3a[_0x5a64('0x35')];if(this['channels'][_0x3fcf3a['uniqueid']][_0x5a64('0x32')]>0x0){tiff2pdf(_0x3fcf3a[_0x5a64('0x2f')],_0x5a64('0x36'),function(_0x4429ed){logger[_0x5a64('0x25')](_0x3fcf3a[_0x5a64('0x22')],_0x5a64('0x37'),_0x4429ed[_0x5a64('0x38')]);attachment[_0x5a64('0x39')]({'name':path[_0x5a64('0x3a')](_0x3fcf3a['filename'])['name'],'basename':path[_0x5a64('0x3a')](_0x3fcf3a[_0x5a64('0x2f')])[_0x5a64('0x24')]+_0x5a64('0x3b'),'type':_0x5a64('0x3c')})[_0x5a64('0x3d')](function(_0xad97b2){faxAccount[_0x5a64('0x3e')](_0x956ac1,{'from':_0x3fcf3a['calleridnum'],'mapKey':_0x5a64('0x3f'),'body':path[_0x5a64('0x3a')](_0x3fcf3a[_0x5a64('0x2f')])['name']+_0x5a64('0x3b'),'AttachmentId':_0xad97b2['id']})['catch'](function(_0x2f0c74){logger[_0x5a64('0x40')](_0x3fcf3a[_0x5a64('0x22')],'\x20notify\x20',JSON['stringify'](_0x2f0c74));});})[_0x5a64('0x41')](function(_0x7e3363){logger[_0x5a64('0x40')](_0x3fcf3a[_0x5a64('0x22')],_0x5a64('0x42'),JSON[_0x5a64('0x43')](_0x7e3363));});});}logger[_0x5a64('0x25')](_0x3fcf3a[_0x5a64('0x22')],'\x20receiveFax\x20');}};Fax[_0x5a64('0x1d')][_0x5a64('0x1c')]=function(_0x35e176){if(this[_0x5a64('0x44')][_0x35e176[_0x5a64('0x22')]]){_[_0x5a64('0x45')](this[_0x5a64('0xc')][_0x35e176[_0x5a64('0x22')]],_[_0x5a64('0x46')](_0x35e176,['response',_0x5a64('0x47')]));}};function updateStatus(_0x486c6b){if(_0x486c6b[_0x5a64('0x48')]){faxMessage[_0x5a64('0x49')](_0x486c6b[_0x5a64('0x48')],{'failMessage':'SENDING\x20FAILED\x20'})[_0x5a64('0x3d')](function(_0x4ba9eb){ut[_0x5a64('0x4a')](_0x5a64('0x4b'),_0x4ba9eb);})[_0x5a64('0x41')](function(_0x2a4c7d){ut[_0x5a64('0x4a')](_0x5a64('0x4c'),_0x2a4c7d);});}else{ut['logger'](_0x5a64('0x4d'));}}Fax[_0x5a64('0x1d')][_0x5a64('0x4e')]=function(_0x2e2a86,_0x361ad1,_0x642a2d){var _0x59806a=this;var _0x388503={};if(_0x361ad1){_0x388503={'read':_0x361ad1};}else{_0x388503={'failMessage':_0x642a2d};}if(this[_0x5a64('0x44')][_0x2e2a86][_0x5a64('0x48')]){faxMessage['update'](this[_0x5a64('0x44')][_0x2e2a86]['AttachmentId'],_0x388503)[_0x5a64('0x3d')](function(_0x1d3d01){ut[_0x5a64('0x4a')]('[Fax][Message][Updated]',_0x1d3d01);})['catch'](function(_0x8358be){ut[_0x5a64('0x4a')](_0x5a64('0x4f'),_0x8358be);})[_0x5a64('0x50')](function(){delete _0x59806a['channels'][_0x2e2a86];delete _0x59806a[_0x5a64('0x44')][_0x2e2a86];});}else{ut[_0x5a64('0x4a')]('[Fax][Message][NoUpdate2]');delete this[_0x5a64('0xc')][_0x2e2a86];delete this[_0x5a64('0x44')][_0x2e2a86];}};Fax[_0x5a64('0x1d')][_0x5a64('0x1a')]=function(_0x471ca6){var _0x23878d=this;if(this[_0x5a64('0xc')][_0x471ca6[_0x5a64('0x22')]]){if(this['actions'][_0x471ca6['uniqueid']]){this[_0x5a64('0xc')][_0x471ca6[_0x5a64('0x22')]]['id']=this[_0x5a64('0x44')][_0x471ca6['uniqueid']]['id'];this[_0x5a64('0xc')][_0x471ca6['uniqueid']]['name']=this[_0x5a64('0x44')][_0x471ca6[_0x5a64('0x22')]][_0x5a64('0x24')];}logger[_0x5a64('0x25')](_0x471ca6[_0x5a64('0x22')],this[_0x5a64('0x44')][_0x471ca6['uniqueid']]?_0x5a64('0x51'):_0x5a64('0x52'),JSON[_0x5a64('0x43')](this[_0x5a64('0xc')][_0x471ca6[_0x5a64('0x22')]]));if(this[_0x5a64('0x44')][_0x471ca6[_0x5a64('0x22')]]){if(this[_0x5a64('0xc')][_0x471ca6[_0x5a64('0x22')]][_0x5a64('0x53')]>0x0&&this['channels'][_0x471ca6[_0x5a64('0x22')]][_0x5a64('0x15')]===_0x5a64('0x54')){this['updateStatus'](_0x471ca6[_0x5a64('0x22')],!![]);}else{this['updateStatus'](_0x471ca6['uniqueid'],![],this[_0x5a64('0xc')][_0x471ca6[_0x5a64('0x22')]][_0x5a64('0x55')]?_0x5a64('0x56')+this[_0x5a64('0xc')][_0x471ca6['uniqueid']][_0x5a64('0x55')]:_0x5a64('0x57'));}}}};Fax['prototype'][_0x5a64('0x58')]=function(_0xe9fce3){var _0x3fb457=this;return new BPromise(function(_0x4c0f80,_0x292b94){_0x3fb457[_0x5a64('0x59')](_0xe9fce3,_0x3fb457[_0x5a64('0xd')][_0xe9fce3[_0x5a64('0x5a')]])[_0x5a64('0x3d')](function(_0x5b193f){ut[_0x5a64('0x4a')](_0x5a64('0x5b'),_0x5b193f);_0x4c0f80(ut['message'](_0x5a64('0x5c')));})[_0x5a64('0x41')](function(_0x186d63){ut[_0x5a64('0x4a')](_0x5a64('0x5d'),_0x186d63);updateStatus(_0xe9fce3);_0x292b94(ut[_0x5a64('0x38')](_0x5a64('0x5e')));});});};Fax[_0x5a64('0x1d')][_0x5a64('0x5f')]=function(_0x41c95a){var _0x526ef2=this;return new BPromise(function(_0x35c97e,_0x475329){var _0x274d51=_0x526ef2[_0x5a64('0x60')](_0x526ef2[_0x5a64('0xd')][_0x41c95a[_0x5a64('0x5a')]]['Trunk'],_0x41c95a);if(_0x274d51[_0x5a64('0x61')]){_0x35c97e(ut[_0x5a64('0x38')]('Trunk\x20Reachable'));}else{_0x475329(ut[_0x5a64('0x38')](_0x274d51[_0x5a64('0x38')]));}});};function originate(_0x2b4c88,_0x3aee6b,_0x408b84){return new BPromise(function(_0x393d7a,_0x51db25){if(_0x408b84){var _0x1bd473=util[_0x5a64('0x62')](_0x5a64('0x63'),path['parse'](_0x2b4c88[_0x5a64('0x64')])[_0x5a64('0x24')],_0x2b4c88[_0x5a64('0x64')]);gs[_0x5a64('0x65')](_0x1bd473)[_0x5a64('0x3d')](function(){_0x2b4c88[_0x5a64('0x64')]=util[_0x5a64('0x62')](_0x5a64('0x66'),path[_0x5a64('0x3a')](_0x2b4c88[_0x5a64('0x64')])[_0x5a64('0x67')],path[_0x5a64('0x3a')](_0x2b4c88[_0x5a64('0x64')])[_0x5a64('0x24')]);_0x3aee6b[_0x5a64('0x68')]=_0x2b4c88[_0x5a64('0x64')];ut[_0x5a64('0x4a')](_0x5a64('0x69'),'');ami[_0x5a64('0x6a')](ut[_0x5a64('0x6b')](_0x2b4c88,_0x3aee6b))[_0x5a64('0x3d')](function(_0x285664){_0x393d7a(_0x285664);})[_0x5a64('0x41')](function(_0x315dfa){_0x51db25(_0x315dfa);});})[_0x5a64('0x41')](function(_0x2f1c16){_0x51db25(_0x2f1c16);});}else{ami[_0x5a64('0x6a')](ut[_0x5a64('0x6b')](_0x2b4c88,_0x3aee6b))['then'](function(_0x2065ff){_0x393d7a(_0x2065ff);})['catch'](function(_0x51b71f){_0x51db25(_0x51b71f);});}});}Fax[_0x5a64('0x1d')][_0x5a64('0x59')]=function(_0x414e35,_0x3bce59){var _0x100571=this;return new BPromise(function(_0x244ad6,_0x2645d6){var _0x27ab73=uuid['v4']();var _0x2bdb2f=ut[_0x5a64('0x6c')](_0x414e35,_0x3bce59);_0x100571['actions'][_0x27ab73]=new Action(_0x27ab73,_0x3bce59,_0x414e35);var _0x2a1333=_0x100571[_0x5a64('0x44')][_0x27ab73];if(path[_0x5a64('0x3a')](_0x414e35[_0x5a64('0x64')])[_0x5a64('0x6d')]===_0x5a64('0x3b')){originate(_0x2a1333,_0x2bdb2f,!![])[_0x5a64('0x3d')](function(_0x55e7c8){_0x244ad6(_0x55e7c8);})['catch'](function(_0x2eecb3){_0x2645d6(_0x2eecb3);});}else{originate(_0x2a1333,_0x2bdb2f,![])[_0x5a64('0x3d')](function(_0x24ebb9){_0x244ad6(_0x24ebb9);})[_0x5a64('0x41')](function(_0x370aa8){_0x2645d6(_0x370aa8);});}});};Fax['prototype'][_0x5a64('0x6e')]=function(_0x2345ce){return!_[_0x5a64('0x6f')](_0x2345ce)&&!_[_0x5a64('0x6f')](_0x2345ce['name'])&&!_['isNil'](_0x2345ce['active'])&&_0x2345ce[_0x5a64('0x70')]&&!_['isNil'](this['trunks'][util[_0x5a64('0x62')](_0x5a64('0x71'),_0x2345ce[_0x5a64('0x24')])])&&!_[_0x5a64('0x6f')](this[_0x5a64('0xe')][util['format'](_0x5a64('0x71'),_0x2345ce[_0x5a64('0x24')])][_0x5a64('0x72')])&&(this[_0x5a64('0xe')][util['format']('SIP/%s',_0x2345ce['name'])]['status']===_0x5a64('0x73')||this[_0x5a64('0xe')][util[_0x5a64('0x62')](_0x5a64('0x71'),_0x2345ce['name'])][_0x5a64('0x72')]==='unmonitored');};Fax[_0x5a64('0x1d')][_0x5a64('0x60')]=function(_0x4ee425,_0x5b35ba){if(!this['isTrunkReachable'](_0x4ee425)){ut[_0x5a64('0x4a')](_0x5a64('0x74'),_[_0x5a64('0x6f')](_0x4ee425)?'':_0x4ee425['name']+'\x20Trunk\x20is\x20not\x20active');return{'isValid':![],'message':_0x5a64('0x75')};}if(_[_0x5a64('0x6f')](_0x5b35ba[_0x5a64('0x3f')])){ut['logger'](_0x5a64('0x76'),JSON[_0x5a64('0x43')](_0x5b35ba));return{'isValid':![],'message':_0x5a64('0x77')};}if(_[_0x5a64('0x6f')](_0x5b35ba[_0x5a64('0x64')])){ut[_0x5a64('0x4a')](_0x5a64('0x78'),JSON[_0x5a64('0x43')](_0x5b35ba));return{'isValid':![],'message':_0x5a64('0x79')};}return{'isValid':!![],'message':_0x5a64('0x7a')};};module['exports']=Fax;
\ No newline at end of file