Built motion from commit ffdca78c.|2.6.24
[motion2.git] / server / services / ami / fax / index.js
index c3b96cf..5f9bf0b 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x6bf9=['isNil','active','SIP/%s','[Fax][checkTrunk][Trunk\x20not\x20working\x20correctly]','\x20Trunk\x20is\x20not\x20active','Trunk\x20not\x20working\x20correctly','Empty\x20Fax','[Fax][checkTrunk][Empty\x20path]','Is\x20Valid','util','lodash','bluebird','uuid','moment','../../../config/logger','fax','../ami','./rpcDb','./channel','./util/util','../rpc/faxAccount','../rpc/faxMessage','faxAccounts','trunks','actions','newchannel','bind','newstate','syncNewState','syncNewExten','faxstatus','syncFaxStatus','syncReceiveFax','hangup','syncHangup','syncOriginateResponse','prototype','syncNewchannel','context','from-voip-provider','hasOwnProperty','localstationid','channels','uniqueid','channel','name','\x20syncNewchannel\x20','info','syncVarSet','variable','channelstatedesc','operation','status','filename','\x20syncFaxStatus\x20','remotestationid','pagestransferred','resolution','transferrate','calleridnum','/var/opt/motion2/server/files/attachments/','create','parse','.pdf','application/pdf','then','notify','catch','error','\x20notify\x20','stringify','\x20receiveFax\x20','pick','response','AttachmentId','SENDING\x20FAILED\x20','logger','[Fax][Message][Error][NoUpdate1]','[Fax][Message][Error][NoUpdate2]','updateStatus','update','[Fax][Message][Updated]','[Fax][Message][NoUpdate1]','finally','[Fax][Message][NoUpdate2]','\x20hangup\x20sendFile\x20','\x20hangup\x20faxRiceive\x20','faxpages','SUCCESS','faxstatusstring','SENDING\x20FAILED:\x20','execOriginate','FaxAccountId','[Fax][execOriginate][success]','message','Fax\x20received','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','path','execute','%s/%s.tif','XMF-PATH','Convert\x20pdf\x20to\x20tif','Action','addVariables','ext','isTrunkReachable'];(function(_0x419bb9,_0x247ffa){var _0x594006=function(_0x795a74){while(--_0x795a74){_0x419bb9['push'](_0x419bb9['shift']());}};_0x594006(++_0x247ffa);}(_0x6bf9,0x1cd));var _0x96bf=function(_0xd4636c,_0x34dbf6){_0xd4636c=_0xd4636c-0x0;var _0x5ee17d=_0x6bf9[_0xd4636c];return _0x5ee17d;};'use strict';var util=require(_0x96bf('0x0'));var _=require(_0x96bf('0x1'));var BPromise=require(_0x96bf('0x2'));var uuid=require(_0x96bf('0x3'));var moment=require(_0x96bf('0x4'));var path=require('path');var tiff2pdf=require('tiff2pdf');var gs=require('./util/gs');var logger=require(_0x96bf('0x5'))(_0x96bf('0x6'));var ami=require(_0x96bf('0x7'));var rpcDb=require(_0x96bf('0x8'));var Channel=require(_0x96bf('0x9'));var ut=require(_0x96bf('0xa'));var Action=require('./action');var faxAccount=require(_0x96bf('0xb'));var attachment=require('../rpc/attachment');var faxMessage=require(_0x96bf('0xc'));function Fax(_0x100fa4){this['channels']={};this[_0x96bf('0xd')]=_0x100fa4[_0x96bf('0xd')];this[_0x96bf('0xe')]=_0x100fa4['trunks'];this[_0x96bf('0xf')]={};ami['on'](_0x96bf('0x10'),this['syncNewchannel'][_0x96bf('0x11')](this));ami['on']('varset',this['syncVarSet']['bind'](this));ami['on'](_0x96bf('0x12'),this[_0x96bf('0x13')][_0x96bf('0x11')](this));ami['on']('newexten',this[_0x96bf('0x14')][_0x96bf('0x11')](this));ami['on'](_0x96bf('0x15'),this[_0x96bf('0x16')][_0x96bf('0x11')](this));ami['on']('receivefax',this[_0x96bf('0x17')][_0x96bf('0x11')](this));ami['on'](_0x96bf('0x18'),this[_0x96bf('0x19')][_0x96bf('0x11')](this));ami['on']('originateresponse',this[_0x96bf('0x1a')]['bind'](this));}Fax[_0x96bf('0x1b')][_0x96bf('0x1c')]=function(_0x2ca19e){if(_0x2ca19e[_0x96bf('0x1d')]===_0x96bf('0x1e')){for(var _0x37ec0d in this[_0x96bf('0xd')]){if(this[_0x96bf('0xd')][_0x96bf('0x1f')](_0x37ec0d)){if(_0x2ca19e['exten']===this['faxAccounts'][_0x37ec0d][_0x96bf('0x20')]){this[_0x96bf('0x21')][_0x2ca19e[_0x96bf('0x22')]]={};this['channels'][_0x2ca19e[_0x96bf('0x22')]][_0x96bf('0x23')]=_0x2ca19e[_0x96bf('0x23')];this[_0x96bf('0x21')][_0x2ca19e[_0x96bf('0x22')]]['id']=this[_0x96bf('0xd')][_0x37ec0d]['id'];this['channels'][_0x2ca19e['uniqueid']][_0x96bf('0x24')]=this[_0x96bf('0xd')][_0x37ec0d][_0x96bf('0x24')];logger['info'](_0x2ca19e[_0x96bf('0x22')],_0x96bf('0x25'));}}}}if(this[_0x96bf('0xf')][_0x2ca19e[_0x96bf('0x22')]]){this[_0x96bf('0x21')][_0x2ca19e[_0x96bf('0x22')]]={};this[_0x96bf('0x21')][_0x2ca19e['uniqueid']]['channel']=_0x2ca19e[_0x96bf('0x23')];logger[_0x96bf('0x26')](_0x2ca19e[_0x96bf('0x22')],_0x96bf('0x25'));}};Fax[_0x96bf('0x1b')][_0x96bf('0x27')]=function(_0x4152f6){if(this[_0x96bf('0x21')][_0x4152f6[_0x96bf('0x22')]]){for(var _0x3e6bfc in _0x4152f6[_0x96bf('0x28')]){if(_0x4152f6[_0x96bf('0x28')][_0x96bf('0x1f')](_0x3e6bfc)){this[_0x96bf('0x21')][_0x4152f6['uniqueid']][_0x3e6bfc]=_0x4152f6['value'];}}}};Fax['prototype'][_0x96bf('0x13')]=function(_0xe05730){if(this[_0x96bf('0x21')][_0xe05730['uniqueid']]){this[_0x96bf('0x21')][_0xe05730[_0x96bf('0x22')]]['channelstate']=_0xe05730['channelstate'];this[_0x96bf('0x21')][_0xe05730[_0x96bf('0x22')]][_0x96bf('0x29')]=_0xe05730[_0x96bf('0x29')];}};Fax[_0x96bf('0x1b')]['syncNewExten']=function(_0x20e7c4){if(this[_0x96bf('0x21')][_0x20e7c4['uniqueid']]){for(var _0x35b2f6 in _0x20e7c4['variable']){if(_0x20e7c4[_0x96bf('0x28')][_0x96bf('0x1f')](_0x35b2f6)){this[_0x96bf('0x21')][_0x20e7c4['uniqueid']][_0x35b2f6]=_0x20e7c4['value'];}}}};Fax['prototype'][_0x96bf('0x16')]=function(_0x126eeb){if(this[_0x96bf('0x21')][_0x126eeb[_0x96bf('0x22')]]){this[_0x96bf('0x21')][_0x126eeb[_0x96bf('0x22')]][_0x96bf('0x2a')]=_0x126eeb[_0x96bf('0x2a')];this[_0x96bf('0x21')][_0x126eeb[_0x96bf('0x22')]]['status']=_0x126eeb[_0x96bf('0x2b')];this[_0x96bf('0x21')][_0x126eeb[_0x96bf('0x22')]]['localstationid']=_0x126eeb[_0x96bf('0x20')];this[_0x96bf('0x21')][_0x126eeb[_0x96bf('0x22')]][_0x96bf('0x2c')]=_0x126eeb['filename'];logger[_0x96bf('0x26')](_0x126eeb['uniqueid'],_0x96bf('0x2d'));}};Fax['prototype'][_0x96bf('0x17')]=function(_0x4595d5){var _0x4646c7=this;if(this[_0x96bf('0x21')][_0x4595d5[_0x96bf('0x22')]]){var _0x1cbeec=this[_0x96bf('0x21')][_0x4595d5[_0x96bf('0x22')]]['id'];this[_0x96bf('0x21')][_0x4595d5['uniqueid']][_0x96bf('0x2e')]=_0x4595d5['remotestationid'];this[_0x96bf('0x21')][_0x4595d5['uniqueid']]['pagestransferred']=_0x4595d5[_0x96bf('0x2f')];this[_0x96bf('0x21')][_0x4595d5[_0x96bf('0x22')]][_0x96bf('0x20')]=_0x4595d5['localstationid'];this[_0x96bf('0x21')][_0x4595d5[_0x96bf('0x22')]]['resolution']=_0x4595d5[_0x96bf('0x30')];this['channels'][_0x4595d5[_0x96bf('0x22')]]['transferrate']=_0x4595d5[_0x96bf('0x31')];this[_0x96bf('0x21')][_0x4595d5[_0x96bf('0x22')]][_0x96bf('0x2c')]=_0x4595d5['filename'];this[_0x96bf('0x21')][_0x4595d5[_0x96bf('0x22')]][_0x96bf('0x32')]=_0x4595d5[_0x96bf('0x32')];if(this[_0x96bf('0x21')][_0x4595d5[_0x96bf('0x22')]]['pagestransferred']>0x0){tiff2pdf(_0x4595d5[_0x96bf('0x2c')],_0x96bf('0x33'),function(_0x888bb){logger[_0x96bf('0x26')](_0x4595d5[_0x96bf('0x22')],'\x20result\x20conversion\x20file\x20',_0x888bb['message']);attachment[_0x96bf('0x34')]({'name':path[_0x96bf('0x35')](_0x4595d5[_0x96bf('0x2c')])[_0x96bf('0x24')],'basename':path[_0x96bf('0x35')](_0x4595d5[_0x96bf('0x2c')])[_0x96bf('0x24')]+_0x96bf('0x36'),'type':_0x96bf('0x37')})[_0x96bf('0x38')](function(_0x54546b){faxAccount[_0x96bf('0x39')](_0x1cbeec,{'from':_0x4595d5[_0x96bf('0x32')],'mapKey':_0x96bf('0x6'),'body':path[_0x96bf('0x35')](_0x4595d5[_0x96bf('0x2c')])[_0x96bf('0x24')]+_0x96bf('0x36'),'AttachmentId':_0x54546b['id']})[_0x96bf('0x3a')](function(_0x4d11b7){logger[_0x96bf('0x3b')](_0x4595d5['uniqueid'],_0x96bf('0x3c'),JSON['stringify'](_0x4d11b7));});})[_0x96bf('0x3a')](function(_0x5286de){logger[_0x96bf('0x3b')](_0x4595d5[_0x96bf('0x22')],'\x20receiveFax\x20',JSON[_0x96bf('0x3d')](_0x5286de));});});}logger[_0x96bf('0x26')](_0x4595d5[_0x96bf('0x22')],_0x96bf('0x3e'));}};Fax[_0x96bf('0x1b')][_0x96bf('0x1a')]=function(_0x3149c3){if(this[_0x96bf('0xf')][_0x3149c3[_0x96bf('0x22')]]){_['merge'](this[_0x96bf('0x21')][_0x3149c3[_0x96bf('0x22')]],_[_0x96bf('0x3f')](_0x3149c3,[_0x96bf('0x40'),'reason']));}};function updateStatus(_0x3ae7c1){if(_0x3ae7c1[_0x96bf('0x41')]){faxMessage['update'](_0x3ae7c1[_0x96bf('0x41')],{'failMessage':_0x96bf('0x42')})[_0x96bf('0x38')](function(_0x54e2a6){ut[_0x96bf('0x43')]('[Fax][Message][Error][Updated]',_0x54e2a6);})[_0x96bf('0x3a')](function(_0x5c4391){ut['logger'](_0x96bf('0x44'),_0x5c4391);});}else{ut[_0x96bf('0x43')](_0x96bf('0x45'));}}Fax[_0x96bf('0x1b')][_0x96bf('0x46')]=function(_0x58a65d,_0x4b5297,_0x3afb30){var _0x1b44b8=this;var _0x315571={};if(_0x4b5297){_0x315571={'read':_0x4b5297};}else{_0x315571={'failMessage':_0x3afb30};}if(this[_0x96bf('0xf')][_0x58a65d][_0x96bf('0x41')]){faxMessage[_0x96bf('0x47')](this[_0x96bf('0xf')][_0x58a65d][_0x96bf('0x41')],_0x315571)['then'](function(_0x2d1c6a){ut[_0x96bf('0x43')](_0x96bf('0x48'),_0x2d1c6a);})[_0x96bf('0x3a')](function(_0x102f35){ut[_0x96bf('0x43')](_0x96bf('0x49'),_0x102f35);})[_0x96bf('0x4a')](function(){delete _0x1b44b8['channels'][_0x58a65d];delete _0x1b44b8[_0x96bf('0xf')][_0x58a65d];});}else{ut[_0x96bf('0x43')](_0x96bf('0x4b'));delete this[_0x96bf('0x21')][_0x58a65d];delete this['actions'][_0x58a65d];}};Fax[_0x96bf('0x1b')][_0x96bf('0x19')]=function(_0x27ccb6){var _0x1a05c1=this;if(this[_0x96bf('0x21')][_0x27ccb6[_0x96bf('0x22')]]){if(this[_0x96bf('0xf')][_0x27ccb6[_0x96bf('0x22')]]){this['channels'][_0x27ccb6[_0x96bf('0x22')]]['id']=this[_0x96bf('0xf')][_0x27ccb6[_0x96bf('0x22')]]['id'];this[_0x96bf('0x21')][_0x27ccb6[_0x96bf('0x22')]][_0x96bf('0x24')]=this[_0x96bf('0xf')][_0x27ccb6[_0x96bf('0x22')]][_0x96bf('0x24')];}logger[_0x96bf('0x26')](_0x27ccb6['uniqueid'],this[_0x96bf('0xf')][_0x27ccb6[_0x96bf('0x22')]]?_0x96bf('0x4c'):_0x96bf('0x4d'),JSON[_0x96bf('0x3d')](this[_0x96bf('0x21')][_0x27ccb6[_0x96bf('0x22')]]));if(this[_0x96bf('0xf')][_0x27ccb6[_0x96bf('0x22')]]){if(this[_0x96bf('0x21')][_0x27ccb6[_0x96bf('0x22')]][_0x96bf('0x4e')]>0x0&&this[_0x96bf('0x21')][_0x27ccb6[_0x96bf('0x22')]]['faxstatus']===_0x96bf('0x4f')){this[_0x96bf('0x46')](_0x27ccb6['uniqueid'],!![]);}else{this[_0x96bf('0x46')](_0x27ccb6['uniqueid'],![],this[_0x96bf('0x21')][_0x27ccb6[_0x96bf('0x22')]][_0x96bf('0x50')]?_0x96bf('0x51')+this['channels'][_0x27ccb6[_0x96bf('0x22')]]['faxstatusstring']:'SENDING\x20FAILED');}}}};Fax[_0x96bf('0x1b')]['send']=function(_0x312ccb){var _0x17a9a8=this;return new BPromise(function(_0x2050bd,_0x58fbfd){_0x17a9a8[_0x96bf('0x52')](_0x312ccb,_0x17a9a8[_0x96bf('0xd')][_0x312ccb[_0x96bf('0x53')]])['then'](function(_0xb2e120){ut[_0x96bf('0x43')](_0x96bf('0x54'),_0xb2e120);_0x2050bd(ut[_0x96bf('0x55')](_0x96bf('0x56')));})['catch'](function(_0x39367e){ut[_0x96bf('0x43')]('[Fax][execOriginate][failure]',_0x39367e);updateStatus(_0x312ccb);_0x58fbfd(ut[_0x96bf('0x55')](_0x96bf('0x57')));});});};Fax[_0x96bf('0x1b')][_0x96bf('0x58')]=function(_0x48be11){var _0x31b3d0=this;return new BPromise(function(_0x42b55a,_0x15340e){var _0x3a0b09=_0x31b3d0[_0x96bf('0x59')](_0x31b3d0[_0x96bf('0xd')][_0x48be11[_0x96bf('0x53')]][_0x96bf('0x5a')],_0x48be11);if(_0x3a0b09[_0x96bf('0x5b')]){_0x42b55a(ut['message'](_0x96bf('0x5c')));}else{_0x15340e(ut[_0x96bf('0x55')](_0x3a0b09[_0x96bf('0x55')]));}});};function originate(_0x5f240c,_0x34db8a,_0xa0076){return new BPromise(function(_0x15ce03,_0x2b326b){if(_0xa0076){var _0x585eb3=util[_0x96bf('0x5d')](_0x96bf('0x5e'),path['parse'](_0x5f240c['path'])[_0x96bf('0x24')],_0x5f240c[_0x96bf('0x5f')]);gs[_0x96bf('0x60')](_0x585eb3)[_0x96bf('0x38')](function(){_0x5f240c[_0x96bf('0x5f')]=util['format'](_0x96bf('0x61'),path[_0x96bf('0x35')](_0x5f240c[_0x96bf('0x5f')])['dir'],path['parse'](_0x5f240c['path'])['name']);_0x34db8a[_0x96bf('0x62')]=_0x5f240c[_0x96bf('0x5f')];ut[_0x96bf('0x43')](_0x96bf('0x63'),'');ami[_0x96bf('0x64')](ut['variablesAction'](_0x5f240c,_0x34db8a))[_0x96bf('0x38')](function(_0x146e10){_0x15ce03(_0x146e10);})[_0x96bf('0x3a')](function(_0x5cde67){_0x2b326b(_0x5cde67);});})[_0x96bf('0x3a')](function(_0x122c61){_0x2b326b(_0x122c61);});}else{ami[_0x96bf('0x64')](ut['variablesAction'](_0x5f240c,_0x34db8a))[_0x96bf('0x38')](function(_0xd20219){_0x15ce03(_0xd20219);})[_0x96bf('0x3a')](function(_0x325c73){_0x2b326b(_0x325c73);});}});}Fax[_0x96bf('0x1b')][_0x96bf('0x52')]=function(_0x5dca6f,_0x462e5d){var _0x2b3150=this;return new BPromise(function(_0x4dffea,_0xef1ab5){var _0x2740b2=uuid['v4']();var _0x7cec90=ut[_0x96bf('0x65')](_0x5dca6f,_0x462e5d);_0x2b3150[_0x96bf('0xf')][_0x2740b2]=new Action(_0x2740b2,_0x462e5d,_0x5dca6f);var _0x5b52f3=_0x2b3150[_0x96bf('0xf')][_0x2740b2];if(path[_0x96bf('0x35')](_0x5dca6f[_0x96bf('0x5f')])[_0x96bf('0x66')]==='.pdf'){originate(_0x5b52f3,_0x7cec90,!![])[_0x96bf('0x38')](function(_0xfd918c){_0x4dffea(_0xfd918c);})[_0x96bf('0x3a')](function(_0x29983a){_0xef1ab5(_0x29983a);});}else{originate(_0x5b52f3,_0x7cec90,![])[_0x96bf('0x38')](function(_0x2a786b){_0x4dffea(_0x2a786b);})[_0x96bf('0x3a')](function(_0x2ff4f5){_0xef1ab5(_0x2ff4f5);});}});};Fax[_0x96bf('0x1b')][_0x96bf('0x67')]=function(_0x2015c0){return!_[_0x96bf('0x68')](_0x2015c0)&&!_['isNil'](_0x2015c0[_0x96bf('0x24')])&&!_[_0x96bf('0x68')](_0x2015c0[_0x96bf('0x69')])&&_0x2015c0[_0x96bf('0x69')]&&!_[_0x96bf('0x68')](this[_0x96bf('0xe')][util[_0x96bf('0x5d')](_0x96bf('0x6a'),_0x2015c0[_0x96bf('0x24')])])&&!_[_0x96bf('0x68')](this[_0x96bf('0xe')][util[_0x96bf('0x5d')]('SIP/%s',_0x2015c0['name'])][_0x96bf('0x2b')])&&(this[_0x96bf('0xe')][util[_0x96bf('0x5d')]('SIP/%s',_0x2015c0['name'])][_0x96bf('0x2b')]==='reachable'||this['trunks'][util[_0x96bf('0x5d')](_0x96bf('0x6a'),_0x2015c0[_0x96bf('0x24')])][_0x96bf('0x2b')]==='unmonitored');};Fax[_0x96bf('0x1b')][_0x96bf('0x59')]=function(_0x377d0d,_0xcb8539){if(!this[_0x96bf('0x67')](_0x377d0d)){ut['logger'](_0x96bf('0x6b'),_[_0x96bf('0x68')](_0x377d0d)?'':_0x377d0d[_0x96bf('0x24')]+_0x96bf('0x6c'));return{'isValid':![],'message':_0x96bf('0x6d')};}if(_[_0x96bf('0x68')](_0xcb8539['fax'])){ut['logger']('[Fax][checkTrunk][Empty\x20Fax]',JSON['stringify'](_0xcb8539));return{'isValid':![],'message':_0x96bf('0x6e')};}if(_[_0x96bf('0x68')](_0xcb8539['path'])){ut[_0x96bf('0x43')](_0x96bf('0x6f'),JSON[_0x96bf('0x3d')](_0xcb8539));return{'isValid':![],'message':'Empty\x20path'};}return{'isValid':!![],'message':_0x96bf('0x70')};};module['exports']=Fax;
\ No newline at end of file
+var _0x2769=['../rpc/attachment','../rpc/faxMessage','channels','faxAccounts','trunks','actions','newchannel','syncNewchannel','bind','syncVarSet','newstate','syncNewState','syncNewExten','syncFaxStatus','receivefax','syncReceiveFax','syncOriginateResponse','prototype','context','from-voip-provider','localstationid','uniqueid','channel','name','info','\x20syncNewchannel\x20','variable','hasOwnProperty','value','channelstate','channelstatedesc','operation','status','filename','\x20syncFaxStatus\x20','remotestationid','pagestransferred','resolution','transferrate','calleridnum','parse','.pdf','then','notify','error','\x20notify\x20','stringify','\x20receiveFax\x20','merge','pick','response','reason','AttachmentId','update','SENDING\x20FAILED\x20','logger','[Fax][Message][Error][Updated]','catch','[Fax][Message][Error][NoUpdate2]','updateStatus','[Fax][Message][NoUpdate1]','finally','[Fax][Message][NoUpdate2]','\x20hangup\x20faxRiceive\x20','faxpages','SUCCESS','SENDING\x20FAILED:\x20','faxstatusstring','send','FaxAccountId','message','[Fax][execOriginate][failure]','Fax\x20failed','checkTrunk','Trunk','isValid','Trunk\x20Reachable','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','format','dir','Convert\x20pdf\x20to\x20tif','Action','variablesAction','ext','isNil','active','SIP/%s','isTrunkReachable','[Fax][checkTrunk][Trunk\x20not\x20working\x20correctly]','\x20Trunk\x20is\x20not\x20active','fax','[Fax][checkTrunk][Empty\x20Fax]','Empty\x20Fax','[Fax][checkTrunk][Empty\x20path]','Empty\x20path','Is\x20Valid','exports','lodash','uuid','moment','path','tiff2pdf','./util/gs','../../../config/logger','../ami','./channel','./util/util','../rpc/faxAccount'];(function(_0x119216,_0x744cae){var _0x478675=function(_0x2367da){while(--_0x2367da){_0x119216['push'](_0x119216['shift']());}};_0x478675(++_0x744cae);}(_0x2769,0xcf));var _0x9276=function(_0x4382bc,_0x231a2d){_0x4382bc=_0x4382bc-0x0;var _0x13c82a=_0x2769[_0x4382bc];return _0x13c82a;};'use strict';var util=require('util');var _=require(_0x9276('0x0'));var BPromise=require('bluebird');var uuid=require(_0x9276('0x1'));var moment=require(_0x9276('0x2'));var path=require(_0x9276('0x3'));var tiff2pdf=require(_0x9276('0x4'));var gs=require(_0x9276('0x5'));var logger=require(_0x9276('0x6'))('fax');var ami=require(_0x9276('0x7'));var rpcDb=require('./rpcDb');var Channel=require(_0x9276('0x8'));var ut=require(_0x9276('0x9'));var Action=require('./action');var faxAccount=require(_0x9276('0xa'));var attachment=require(_0x9276('0xb'));var faxMessage=require(_0x9276('0xc'));function Fax(_0x552f72){this[_0x9276('0xd')]={};this[_0x9276('0xe')]=_0x552f72[_0x9276('0xe')];this[_0x9276('0xf')]=_0x552f72['trunks'];this[_0x9276('0x10')]={};ami['on'](_0x9276('0x11'),this[_0x9276('0x12')][_0x9276('0x13')](this));ami['on']('varset',this[_0x9276('0x14')][_0x9276('0x13')](this));ami['on'](_0x9276('0x15'),this[_0x9276('0x16')][_0x9276('0x13')](this));ami['on']('newexten',this[_0x9276('0x17')][_0x9276('0x13')](this));ami['on']('faxstatus',this[_0x9276('0x18')]['bind'](this));ami['on'](_0x9276('0x19'),this[_0x9276('0x1a')][_0x9276('0x13')](this));ami['on']('hangup',this['syncHangup']['bind'](this));ami['on']('originateresponse',this[_0x9276('0x1b')][_0x9276('0x13')](this));}Fax[_0x9276('0x1c')]['syncNewchannel']=function(_0x1959d0){if(_0x1959d0[_0x9276('0x1d')]===_0x9276('0x1e')){for(var _0x33d584 in this[_0x9276('0xe')]){if(this[_0x9276('0xe')]['hasOwnProperty'](_0x33d584)){if(_0x1959d0['exten']===this[_0x9276('0xe')][_0x33d584][_0x9276('0x1f')]){this[_0x9276('0xd')][_0x1959d0[_0x9276('0x20')]]={};this[_0x9276('0xd')][_0x1959d0[_0x9276('0x20')]][_0x9276('0x21')]=_0x1959d0[_0x9276('0x21')];this[_0x9276('0xd')][_0x1959d0[_0x9276('0x20')]]['id']=this['faxAccounts'][_0x33d584]['id'];this[_0x9276('0xd')][_0x1959d0[_0x9276('0x20')]][_0x9276('0x22')]=this[_0x9276('0xe')][_0x33d584][_0x9276('0x22')];logger[_0x9276('0x23')](_0x1959d0[_0x9276('0x20')],'\x20syncNewchannel\x20');}}}}if(this[_0x9276('0x10')][_0x1959d0[_0x9276('0x20')]]){this['channels'][_0x1959d0[_0x9276('0x20')]]={};this[_0x9276('0xd')][_0x1959d0[_0x9276('0x20')]][_0x9276('0x21')]=_0x1959d0[_0x9276('0x21')];logger['info'](_0x1959d0[_0x9276('0x20')],_0x9276('0x24'));}};Fax[_0x9276('0x1c')]['syncVarSet']=function(_0xa4f8d0){if(this[_0x9276('0xd')][_0xa4f8d0[_0x9276('0x20')]]){for(var _0x30c5c8 in _0xa4f8d0['variable']){if(_0xa4f8d0[_0x9276('0x25')][_0x9276('0x26')](_0x30c5c8)){this[_0x9276('0xd')][_0xa4f8d0[_0x9276('0x20')]][_0x30c5c8]=_0xa4f8d0[_0x9276('0x27')];}}}};Fax[_0x9276('0x1c')][_0x9276('0x16')]=function(_0x51c705){if(this[_0x9276('0xd')][_0x51c705[_0x9276('0x20')]]){this[_0x9276('0xd')][_0x51c705[_0x9276('0x20')]]['channelstate']=_0x51c705[_0x9276('0x28')];this['channels'][_0x51c705[_0x9276('0x20')]][_0x9276('0x29')]=_0x51c705['channelstatedesc'];}};Fax['prototype'][_0x9276('0x17')]=function(_0x55b0d4){if(this[_0x9276('0xd')][_0x55b0d4[_0x9276('0x20')]]){for(var _0x1e2d22 in _0x55b0d4['variable']){if(_0x55b0d4[_0x9276('0x25')][_0x9276('0x26')](_0x1e2d22)){this[_0x9276('0xd')][_0x55b0d4[_0x9276('0x20')]][_0x1e2d22]=_0x55b0d4['value'];}}}};Fax['prototype'][_0x9276('0x18')]=function(_0x7240d6){if(this['channels'][_0x7240d6['uniqueid']]){this[_0x9276('0xd')][_0x7240d6[_0x9276('0x20')]][_0x9276('0x2a')]=_0x7240d6[_0x9276('0x2a')];this[_0x9276('0xd')][_0x7240d6[_0x9276('0x20')]][_0x9276('0x2b')]=_0x7240d6[_0x9276('0x2b')];this['channels'][_0x7240d6[_0x9276('0x20')]][_0x9276('0x1f')]=_0x7240d6['localstationid'];this['channels'][_0x7240d6[_0x9276('0x20')]][_0x9276('0x2c')]=_0x7240d6[_0x9276('0x2c')];logger['info'](_0x7240d6['uniqueid'],_0x9276('0x2d'));}};Fax['prototype'][_0x9276('0x1a')]=function(_0x5348e5){var _0x56e306=this;if(this[_0x9276('0xd')][_0x5348e5[_0x9276('0x20')]]){var _0x149379=this['channels'][_0x5348e5[_0x9276('0x20')]]['id'];this[_0x9276('0xd')][_0x5348e5['uniqueid']][_0x9276('0x2e')]=_0x5348e5['remotestationid'];this[_0x9276('0xd')][_0x5348e5[_0x9276('0x20')]][_0x9276('0x2f')]=_0x5348e5[_0x9276('0x2f')];this[_0x9276('0xd')][_0x5348e5['uniqueid']][_0x9276('0x1f')]=_0x5348e5[_0x9276('0x1f')];this[_0x9276('0xd')][_0x5348e5[_0x9276('0x20')]][_0x9276('0x30')]=_0x5348e5[_0x9276('0x30')];this[_0x9276('0xd')][_0x5348e5[_0x9276('0x20')]][_0x9276('0x31')]=_0x5348e5[_0x9276('0x31')];this['channels'][_0x5348e5[_0x9276('0x20')]][_0x9276('0x2c')]=_0x5348e5[_0x9276('0x2c')];this['channels'][_0x5348e5['uniqueid']][_0x9276('0x32')]=_0x5348e5['calleridnum'];if(this[_0x9276('0xd')][_0x5348e5[_0x9276('0x20')]]['pagestransferred']>0x0){tiff2pdf(_0x5348e5[_0x9276('0x2c')],'/var/opt/motion2/server/files/attachments/',function(_0x12083f){logger[_0x9276('0x23')](_0x5348e5[_0x9276('0x20')],'\x20result\x20conversion\x20file\x20',_0x12083f['message']);attachment['create']({'name':path[_0x9276('0x33')](_0x5348e5[_0x9276('0x2c')])[_0x9276('0x22')],'basename':path[_0x9276('0x33')](_0x5348e5[_0x9276('0x2c')])[_0x9276('0x22')]+_0x9276('0x34'),'type':'application/pdf'})[_0x9276('0x35')](function(_0x2267a2){faxAccount[_0x9276('0x36')](_0x149379,{'from':_0x5348e5[_0x9276('0x32')],'mapKey':'fax','body':path['parse'](_0x5348e5[_0x9276('0x2c')])[_0x9276('0x22')]+_0x9276('0x34'),'AttachmentId':_0x2267a2['id']})['catch'](function(_0x2ead6e){logger[_0x9276('0x37')](_0x5348e5['uniqueid'],_0x9276('0x38'),JSON[_0x9276('0x39')](_0x2ead6e));});})['catch'](function(_0x557b7e){logger['error'](_0x5348e5[_0x9276('0x20')],_0x9276('0x3a'),JSON['stringify'](_0x557b7e));});});}logger[_0x9276('0x23')](_0x5348e5[_0x9276('0x20')],'\x20receiveFax\x20');}};Fax[_0x9276('0x1c')]['syncOriginateResponse']=function(_0x2c8869){if(this[_0x9276('0x10')][_0x2c8869['uniqueid']]){_[_0x9276('0x3b')](this[_0x9276('0xd')][_0x2c8869[_0x9276('0x20')]],_[_0x9276('0x3c')](_0x2c8869,[_0x9276('0x3d'),_0x9276('0x3e')]));}};function updateStatus(_0x18023f){if(_0x18023f[_0x9276('0x3f')]){faxMessage[_0x9276('0x40')](_0x18023f[_0x9276('0x3f')],{'failMessage':_0x9276('0x41')})[_0x9276('0x35')](function(_0x920329){ut[_0x9276('0x42')](_0x9276('0x43'),_0x920329);})[_0x9276('0x44')](function(_0x31edfe){ut[_0x9276('0x42')]('[Fax][Message][Error][NoUpdate1]',_0x31edfe);});}else{ut[_0x9276('0x42')](_0x9276('0x45'));}}Fax[_0x9276('0x1c')][_0x9276('0x46')]=function(_0x1eefaa,_0x3738eb,_0x33c197){var _0x269ea8=this;var _0x83c8a6={};if(_0x3738eb){_0x83c8a6={'read':_0x3738eb};}else{_0x83c8a6={'failMessage':_0x33c197};}if(this[_0x9276('0x10')][_0x1eefaa][_0x9276('0x3f')]){faxMessage[_0x9276('0x40')](this[_0x9276('0x10')][_0x1eefaa]['AttachmentId'],_0x83c8a6)[_0x9276('0x35')](function(_0x3c238d){ut[_0x9276('0x42')]('[Fax][Message][Updated]',_0x3c238d);})['catch'](function(_0x13700f){ut[_0x9276('0x42')](_0x9276('0x47'),_0x13700f);})[_0x9276('0x48')](function(){delete _0x269ea8['channels'][_0x1eefaa];delete _0x269ea8[_0x9276('0x10')][_0x1eefaa];});}else{ut[_0x9276('0x42')](_0x9276('0x49'));delete this[_0x9276('0xd')][_0x1eefaa];delete this[_0x9276('0x10')][_0x1eefaa];}};Fax[_0x9276('0x1c')]['syncHangup']=function(_0x1bd117){var _0x22aa6f=this;if(this['channels'][_0x1bd117['uniqueid']]){if(this[_0x9276('0x10')][_0x1bd117[_0x9276('0x20')]]){this[_0x9276('0xd')][_0x1bd117['uniqueid']]['id']=this[_0x9276('0x10')][_0x1bd117['uniqueid']]['id'];this['channels'][_0x1bd117[_0x9276('0x20')]][_0x9276('0x22')]=this[_0x9276('0x10')][_0x1bd117[_0x9276('0x20')]][_0x9276('0x22')];}logger[_0x9276('0x23')](_0x1bd117[_0x9276('0x20')],this[_0x9276('0x10')][_0x1bd117[_0x9276('0x20')]]?'\x20hangup\x20sendFile\x20':_0x9276('0x4a'),JSON[_0x9276('0x39')](this[_0x9276('0xd')][_0x1bd117['uniqueid']]));if(this['actions'][_0x1bd117[_0x9276('0x20')]]){if(this['channels'][_0x1bd117[_0x9276('0x20')]][_0x9276('0x4b')]>0x0&&this[_0x9276('0xd')][_0x1bd117[_0x9276('0x20')]]['faxstatus']===_0x9276('0x4c')){this[_0x9276('0x46')](_0x1bd117[_0x9276('0x20')],!![]);}else{this[_0x9276('0x46')](_0x1bd117[_0x9276('0x20')],![],this[_0x9276('0xd')][_0x1bd117[_0x9276('0x20')]]['faxstatusstring']?_0x9276('0x4d')+this['channels'][_0x1bd117['uniqueid']][_0x9276('0x4e')]:'SENDING\x20FAILED');}}}};Fax[_0x9276('0x1c')][_0x9276('0x4f')]=function(_0x49f6c3){var _0x12d433=this;return new BPromise(function(_0x3ec3e9,_0x18f13c){_0x12d433['execOriginate'](_0x49f6c3,_0x12d433[_0x9276('0xe')][_0x49f6c3[_0x9276('0x50')]])[_0x9276('0x35')](function(_0x377b19){ut[_0x9276('0x42')]('[Fax][execOriginate][success]',_0x377b19);_0x3ec3e9(ut[_0x9276('0x51')]('Fax\x20received'));})[_0x9276('0x44')](function(_0x357ecd){ut[_0x9276('0x42')](_0x9276('0x52'),_0x357ecd);updateStatus(_0x49f6c3);_0x18f13c(ut['message'](_0x9276('0x53')));});});};Fax[_0x9276('0x1c')]['checkAfterSend']=function(_0xbf2bf9){var _0x56444e=this;return new BPromise(function(_0x576ad7,_0x1a963e){var _0x7ec2f0=_0x56444e[_0x9276('0x54')](_0x56444e[_0x9276('0xe')][_0xbf2bf9['FaxAccountId']][_0x9276('0x55')],_0xbf2bf9);if(_0x7ec2f0[_0x9276('0x56')]){_0x576ad7(ut[_0x9276('0x51')](_0x9276('0x57')));}else{_0x1a963e(ut['message'](_0x7ec2f0['message']));}});};function originate(_0x4bcdea,_0x2814a2,_0x24a66b){return new BPromise(function(_0x456e38,_0x3eb82b){if(_0x24a66b){var _0xf60d91=util['format'](_0x9276('0x58'),path[_0x9276('0x33')](_0x4bcdea[_0x9276('0x3')])[_0x9276('0x22')],_0x4bcdea['path']);gs[_0x9276('0x59')](_0xf60d91)[_0x9276('0x35')](function(){_0x4bcdea['path']=util[_0x9276('0x5a')]('%s/%s.tif',path['parse'](_0x4bcdea[_0x9276('0x3')])[_0x9276('0x5b')],path[_0x9276('0x33')](_0x4bcdea[_0x9276('0x3')])[_0x9276('0x22')]);_0x2814a2['XMF-PATH']=_0x4bcdea[_0x9276('0x3')];ut['logger'](_0x9276('0x5c'),'');ami['Action'](ut['variablesAction'](_0x4bcdea,_0x2814a2))[_0x9276('0x35')](function(_0x41626a){_0x456e38(_0x41626a);})['catch'](function(_0x4bd42a){_0x3eb82b(_0x4bd42a);});})[_0x9276('0x44')](function(_0x4afb1f){_0x3eb82b(_0x4afb1f);});}else{ami[_0x9276('0x5d')](ut[_0x9276('0x5e')](_0x4bcdea,_0x2814a2))[_0x9276('0x35')](function(_0xc6f4be){_0x456e38(_0xc6f4be);})[_0x9276('0x44')](function(_0x29be78){_0x3eb82b(_0x29be78);});}});}Fax[_0x9276('0x1c')]['execOriginate']=function(_0x735348,_0x2f6cdb){var _0x37e97e=this;return new BPromise(function(_0x3c03a0,_0x96c857){var _0x4faf4a=uuid['v4']();var _0x550680=ut['addVariables'](_0x735348,_0x2f6cdb);_0x37e97e[_0x9276('0x10')][_0x4faf4a]=new Action(_0x4faf4a,_0x2f6cdb,_0x735348);var _0x35b864=_0x37e97e[_0x9276('0x10')][_0x4faf4a];if(path[_0x9276('0x33')](_0x735348['path'])[_0x9276('0x5f')]===_0x9276('0x34')){originate(_0x35b864,_0x550680,!![])[_0x9276('0x35')](function(_0x4b0325){_0x3c03a0(_0x4b0325);})[_0x9276('0x44')](function(_0x1e897e){_0x96c857(_0x1e897e);});}else{originate(_0x35b864,_0x550680,![])[_0x9276('0x35')](function(_0x135d23){_0x3c03a0(_0x135d23);})[_0x9276('0x44')](function(_0x31900a){_0x96c857(_0x31900a);});}});};Fax[_0x9276('0x1c')]['isTrunkReachable']=function(_0x5f1281){return!_[_0x9276('0x60')](_0x5f1281)&&!_[_0x9276('0x60')](_0x5f1281[_0x9276('0x22')])&&!_['isNil'](_0x5f1281[_0x9276('0x61')])&&_0x5f1281[_0x9276('0x61')]&&!_[_0x9276('0x60')](this[_0x9276('0xf')][util[_0x9276('0x5a')](_0x9276('0x62'),_0x5f1281['name'])])&&!_[_0x9276('0x60')](this[_0x9276('0xf')][util[_0x9276('0x5a')](_0x9276('0x62'),_0x5f1281['name'])][_0x9276('0x2b')])&&(this[_0x9276('0xf')][util[_0x9276('0x5a')](_0x9276('0x62'),_0x5f1281[_0x9276('0x22')])][_0x9276('0x2b')]==='reachable'||this[_0x9276('0xf')][util[_0x9276('0x5a')](_0x9276('0x62'),_0x5f1281[_0x9276('0x22')])]['status']==='unmonitored');};Fax[_0x9276('0x1c')][_0x9276('0x54')]=function(_0x4440f9,_0xbeeadd){if(!this[_0x9276('0x63')](_0x4440f9)){ut[_0x9276('0x42')](_0x9276('0x64'),_[_0x9276('0x60')](_0x4440f9)?'':_0x4440f9[_0x9276('0x22')]+_0x9276('0x65'));return{'isValid':![],'message':'Trunk\x20not\x20working\x20correctly'};}if(_[_0x9276('0x60')](_0xbeeadd[_0x9276('0x66')])){ut[_0x9276('0x42')](_0x9276('0x67'),JSON[_0x9276('0x39')](_0xbeeadd));return{'isValid':![],'message':_0x9276('0x68')};}if(_['isNil'](_0xbeeadd[_0x9276('0x3')])){ut[_0x9276('0x42')](_0x9276('0x69'),JSON['stringify'](_0xbeeadd));return{'isValid':![],'message':_0x9276('0x6a')};}return{'isValid':!![],'message':_0x9276('0x6b')};};module[_0x9276('0x6c')]=Fax;
\ No newline at end of file