18 var _0xd0d1=['affectedRows','unlink','complete','argv','existsSync','binding','binding\x20doesn\x27t\x20exists','phone\x20is\x20mandatory','firstName','body\x20id\x20mandatory','No\x20agent\x20available','uncaughtException','path','lodash','papaparse','squel','ioredis','../../../config/environment','../../../config/logger','import','redis','defaults','localhost','socket.io-emitter','YYYY-MM-DD\x20HH:mm:ss','test','select','field','phone','from','join','.id\x20=\x20','where','\x20=\x20','.dialCheckDuplicateType\x20IN\x20(','cm_contacts.scheduledat','cm_contacts.id','cm_contacts.ListId','cm_contacts.createdAt','cm_contacts.updatedAt','cm_contacts.priority','cm_contacts.UserId','insert','into','fromQuery','scheduledat','ContactId','ListId','createdAt','updatedAt','priority','UserId','recallme','fields','cm_contacts.ListId\x20=\x20','.CmListId\x20=\x20?','cm_contacts.createdAt\x20=\x20?','cm_contacts.phone\x20NOT\x20IN\x20(?)','cm_hopper','\x22always\x22','\x22onlyIfOpen\x22','toString','cm_contacts.phone','cm_hopper_black','ListId\x20=\x20?','\x20=\x20?','keys','CompanyId','cm_contacts',')\x20NOT\x20IN\x20?','deletedAt\x20IS\x20NULL','id\x20IN\x20?','min_id','info','error','exit','errors','push','message','sequelize','query','spread','catch','main','stringify','send','start','root','server/files/tmp','.csv','header','writeFileSync','parse','length','rows','data','hasOwnProperty','trim','isValid','isNaN','isNumber','includes','agent\x20not\x20exists','email','email\x20wrong\x20format','YYYY-MM-DD','dateOfBirth\x20wrong\x20format\x20(YYYY-MM-DD)','appendFileSync','emit','contact:import:','Abort\x20parser','SystemError','step','duplicates','cm_contacts_','CREATE\x20TABLE\x20','format','isNil','voice_queues_has_cm_lists','voice_queues','VoiceQueueId','voice_queues_has_cm_blacklists','campaigns_has_cm_lists','campaigns','CampaignId','campaigns_has_cm_blacklists','each','then','finish'];(function(_0xc6afa9,_0x3d98ca){var _0x3085db=function(_0xb36ba9){while(--_0xb36ba9){_0xc6afa9['push'](_0xc6afa9['shift']());}};_0x3085db(++_0x3d98ca);}(_0xd0d1,0x10e));var _0x1d0d=function(_0x34a30c,_0x4adf02){_0x34a30c=_0x34a30c-0x0;var _0x489bc7=_0xd0d1[_0x34a30c];return _0x489bc7;};'use strict';var fs=require('fs');var path=require(_0x1d0d('0x0'));var _=require(_0x1d0d('0x1'));var Papa=require(_0x1d0d('0x2'));var util=require('util');var BPromise=require('bluebird');var moment=require('moment');var squel=require(_0x1d0d('0x3'));var Redis=require(_0x1d0d('0x4'));var db=require('../../../mysqldb')['db'];var config=require(_0x1d0d('0x5'));var logger=require(_0x1d0d('0x6'))(_0x1d0d('0x7'));config[_0x1d0d('0x8')]=_[_0x1d0d('0x9')](config[_0x1d0d('0x8')],{'host':_0x1d0d('0xa'),'port':0x18eb});var socket=require(_0x1d0d('0xb'))(new Redis(config[_0x1d0d('0x8')]));var stats={'finish':![],'errors':[],'rows':0x0,'affectedRows':0x0};var results=[];var stopped=![];var NOW=moment()['format'](_0x1d0d('0xc'));function isEmail(_0x292bce){return/^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/[_0x1d0d('0xd')](_0x292bce);}function selectNotIn(_0x19a39e,_0x4ba2f1,_0xd42da6,_0x4b6771,_0x206554){return squel[_0x1d0d('0xe')]()[_0x1d0d('0xf')](_0x1d0d('0x10'))[_0x1d0d('0x11')](_0x4b6771)[_0x1d0d('0x12')](_0x4ba2f1,null,_0x4ba2f1+_0x1d0d('0x13')+_0x4b6771+'.'+_0xd42da6)[_0x1d0d('0x14')](_0x4b6771+'.'+_0xd42da6+_0x1d0d('0x15')+_0x19a39e+'.'+_0xd42da6)['where'](_0x4ba2f1+_0x1d0d('0x16')+_0x206554[_0x1d0d('0x12')]()+')');}function insertCmHopper(_0x4f4043,_0x8e63b9,_0x2741d4,_0x1a2c86,_0x534c98){var _0x4c900c=['cm_contacts.phone',_0x1d0d('0x17'),_0x1d0d('0x18'),_0x1d0d('0x19'),_0x8e63b9+'.'+_0x1a2c86,_0x1d0d('0x1a'),_0x1d0d('0x1b'),_0x1d0d('0x1c'),_0x1d0d('0x1d'),'\x22'+_0x534c98+'\x22'];return squel[_0x1d0d('0x1e')]()[_0x1d0d('0x1f')]('cm_hopper')[_0x1d0d('0x20')]([_0x1d0d('0x10'),_0x1d0d('0x21'),_0x1d0d('0x22'),_0x1d0d('0x23'),_0x1a2c86,_0x1d0d('0x24'),_0x1d0d('0x25'),_0x1d0d('0x26'),_0x1d0d('0x27'),_0x1d0d('0x28')],squel[_0x1d0d('0xe')]()[_0x1d0d('0x29')](_0x4c900c)[_0x1d0d('0x11')](_0x8e63b9)[_0x1d0d('0x12')]('cm_contacts',null,_0x1d0d('0x2a')+_0x8e63b9+'.CmListId')[_0x1d0d('0x12')](_0x2741d4,null,_0x2741d4+_0x1d0d('0x13')+_0x8e63b9+'.'+_0x1a2c86)[_0x1d0d('0x14')](_0x8e63b9+_0x1d0d('0x2b'),_0x4f4043)[_0x1d0d('0x14')](_0x1d0d('0x2c'),NOW)['where'](_0x1d0d('0x2d'),selectNotIn(_0x8e63b9,_0x2741d4,_0x1a2c86,_0x1d0d('0x2e'),[_0x1d0d('0x2f'),_0x1d0d('0x30')]))['where'](_0x1d0d('0x2d'),selectNotIn(_0x8e63b9,_0x2741d4,_0x1a2c86,_0x1d0d('0x2e'),[_0x1d0d('0x2f')])))[_0x1d0d('0x31')]();}function insertCmHopperBlack(_0x514176,_0x5c4cd5,_0x264c29,_0x18494b){var _0x14a11f=[_0x1d0d('0x32'),_0x1d0d('0x18'),_0x1d0d('0x19'),_0x5c4cd5+'.'+_0x18494b,_0x1d0d('0x1a'),_0x1d0d('0x1b')];return squel[_0x1d0d('0x1e')]()[_0x1d0d('0x1f')](_0x1d0d('0x33'))[_0x1d0d('0x20')](['phone',_0x1d0d('0x22'),'ListId',_0x18494b,_0x1d0d('0x24'),'updatedAt'],squel[_0x1d0d('0xe')]()[_0x1d0d('0x29')](_0x14a11f)[_0x1d0d('0x11')](_0x5c4cd5)[_0x1d0d('0x12')]('cm_contacts',null,_0x1d0d('0x2a')+_0x5c4cd5+'.CmListId')[_0x1d0d('0x12')](_0x264c29,null,_0x264c29+'.id\x20=\x20'+_0x5c4cd5+'.'+_0x18494b)['where'](_0x5c4cd5+_0x1d0d('0x2b'),_0x514176)[_0x1d0d('0x14')](_0x1d0d('0x2c'),NOW)[_0x1d0d('0x14')](_0x1d0d('0x2d'),squel[_0x1d0d('0xe')]()['field'](_0x1d0d('0x10'))[_0x1d0d('0x11')](_0x1d0d('0x33'))[_0x1d0d('0x14')](_0x1d0d('0x34'),_0x514176)[_0x1d0d('0x14')](_0x18494b+_0x1d0d('0x35'),_0x5c4cd5+'.'+_0x18494b)))[_0x1d0d('0x31')]();}function insertCmContact(_0x1ecea5,_0x253eae,_0x4d9d37,_0x51a7a0){var _0x486344=_['concat'](_[_0x1d0d('0x36')](_0x51a7a0),[_0x1d0d('0x23'),_0x1d0d('0x37'),_0x1d0d('0x24'),_0x1d0d('0x25')]);return squel[_0x1d0d('0x1e')]()['into'](_0x1d0d('0x38'))['fromQuery'](_0x486344,squel[_0x1d0d('0xe')]()[_0x1d0d('0x29')](_0x486344)['from'](_0x253eae)[_0x1d0d('0x14')]('('+_0x4d9d37['join'](',')+_0x1d0d('0x39'),squel[_0x1d0d('0xe')]()[_0x1d0d('0x29')](_0x4d9d37)[_0x1d0d('0x11')](_0x1d0d('0x38'))['where'](_0x1d0d('0x34'),_0x1ecea5)[_0x1d0d('0x14')](_0x1d0d('0x3a')))[_0x1d0d('0x14')](_0x1d0d('0x3b'),squel[_0x1d0d('0xe')]()[_0x1d0d('0xf')]('MIN(id)',_0x1d0d('0x3c'))[_0x1d0d('0x11')](_0x253eae)['group'](_0x4d9d37['join'](','))))[_0x1d0d('0x31')]();}function handleStop(){logger[_0x1d0d('0x3d')]('Received\x20SIGINT');stopped=!![];}function handleUncaughtException(_0x5eeacc){logger[_0x1d0d('0x3e')](_0x5eeacc['message']);process[_0x1d0d('0x3f')](0x1);}function handleError(_0x3b35b2,_0x49fef8){stats[_0x1d0d('0x40')][_0x1d0d('0x41')]({'name':_0x49fef8['code'],'message':_0x49fef8[_0x1d0d('0x42')],'row':_0x3b35b2});}function handleQuery(_0x3d5418){logger['info'](_0x3d5418);return db[_0x1d0d('0x43')][_0x1d0d('0x44')](_0x3d5418)[_0x1d0d('0x45')](function(_0x160b99){results[_0x1d0d('0x41')](_0x160b99);})[_0x1d0d('0x46')](function(_0x3b3084){logger[_0x1d0d('0x3e')](_0x3b3084[_0x1d0d('0x42')]);});}function main(_0x3191ab,_0x18cd97,_0x43d6d7,_0x2ec020){logger['info'](_0x1d0d('0x47'),_0x3191ab,JSON[_0x1d0d('0x48')](_0x18cd97));process[_0x1d0d('0x49')](_0x1d0d('0x4a'));var _0x24f077=_0x18cd97['binding'];var _0x3942b6=_0x18cd97['socket_timestamp'];var _0x19b99c=path[_0x1d0d('0x12')](config[_0x1d0d('0x4b')],_0x1d0d('0x4c'),_0x3942b6+_0x1d0d('0x4d'));var _0x1a6f7b=_[_0x1d0d('0x36')](_0x24f077)['join']();logger[_0x1d0d('0x3d')](_0x1d0d('0x4e'),_0x1a6f7b);fs[_0x1d0d('0x4f')](_0x19b99c,_0x1a6f7b+'\x0a');Papa[_0x1d0d('0x50')](fs['createReadStream'](_0x3191ab),{'header':!![],'skipEmptyLines':!![],'step':function(_0x5ed5d6,_0x3f2ebd){try{for(var _0x4b7612=0x0,_0x1265d2=[];_0x4b7612<_0x5ed5d6['data'][_0x1d0d('0x51')];_0x4b7612++){stats[_0x1d0d('0x52')]+=0x1;if(_0x5ed5d6['errors'][_0x4b7612]){handleError(_0x5ed5d6[_0x1d0d('0x53')][_0x4b7612],_0x5ed5d6[_0x1d0d('0x40')][_0x4b7612]);}else{var _0x192e88=[];for(var _0x5eb28a in _0x24f077){if(_0x24f077[_0x1d0d('0x54')](_0x5eb28a)){if(_0x5ed5d6[_0x1d0d('0x53')][_0x4b7612][_0x24f077[_0x5eb28a]]){var _0x327f11=_[_0x1d0d('0x55')](_0x5ed5d6[_0x1d0d('0x53')][_0x4b7612][_0x24f077[_0x5eb28a]]['replace'](/"/g,'\x27'));switch(_0x5eb28a){case _0x1d0d('0x21'):var _0x3bdca6=moment(_0x327f11,_0x1d0d('0xc'),!![]);if(_0x3bdca6[_0x1d0d('0x56')]()){_0x1265d2[_0x1d0d('0x41')]('\x22'+_0x327f11+'\x22');}else{_0x192e88[_0x1d0d('0x41')]('scheduledat\x20wrong\x20format\x20(YYYY-MM-DD\x20HH:mm:ss)');}break;case'priority':var _0x3a5a7d=parseInt(_0x327f11);_0x327f11=_[_0x1d0d('0x57')](_0x3a5a7d)||_0x3a5a7d<0x0||_0x3a5a7d>0x4?_0x2ec020?0x3:0x2:_0x3a5a7d;_0x1265d2[_0x1d0d('0x41')]('\x22'+_0x327f11+'\x22');break;case _0x1d0d('0x27'):var _0x3ca315=parseInt(_0x327f11);if(_[_0x1d0d('0x58')](_0x3ca315)&&_[_0x1d0d('0x59')](_0x43d6d7,_0x3ca315)){_0x1265d2[_0x1d0d('0x41')]('\x22'+_0x3ca315+'\x22');}else{_0x192e88[_0x1d0d('0x41')](_0x1d0d('0x5a'));}break;case _0x1d0d('0x5b'):if(isEmail(_0x327f11)){_0x1265d2[_0x1d0d('0x41')]('\x22'+_0x327f11+'\x22');}else{_0x192e88['push'](_0x1d0d('0x5c'));}break;case'dateOfBirth':var _0x4b7d7=moment(_0x327f11,_0x1d0d('0x5d'),!![]);if(_0x4b7d7[_0x1d0d('0x56')]()){_0x1265d2[_0x1d0d('0x41')]('\x22'+_0x327f11+'\x22');}else{_0x192e88['push'](_0x1d0d('0x5e'));}break;default:_0x1265d2[_0x1d0d('0x41')]('\x22'+_0x327f11+'\x22');}}else{switch(_0x5eb28a){case'firstName':case'phone':_0x192e88['push'](_0x5eb28a+'\x20not\x20specified');break;default:_0x1265d2[_0x1d0d('0x41')]('\x22\x22');}}}}if(_0x192e88[_0x1d0d('0x51')]){handleError(_0x5ed5d6[_0x1d0d('0x53')][_0x4b7612],{'code':'SystemRow','message':_0x192e88[_0x1d0d('0x12')]()});}else{fs[_0x1d0d('0x5f')](_0x19b99c,_0x1265d2[_0x1d0d('0x12')]()+'\x0a');}_0x1265d2=[];}if(!(stats['rows']%0xc8)){socket[_0x1d0d('0x60')](_0x1d0d('0x61')+_0x3942b6,stats);stats[_0x1d0d('0x40')]=[];}}if(stopped){logger[_0x1d0d('0x3d')](_0x1d0d('0x62'));_0x3f2ebd['abort']();}}catch(_0x5d4e6e){handleError(_0x5ed5d6[_0x1d0d('0x53')][_0x4b7612],{'code':_0x1d0d('0x63'),'message':_0x5d4e6e['message']});logger[_0x1d0d('0x3e')](_0x1d0d('0x64'),_0x5d4e6e[_0x1d0d('0x42')]);}},'complete':function(){try{var _0x4dfb45=[];var _0x45f035=_0x1d0d('0x38');if(_0x18cd97['duplicates']&&_0x18cd97[_0x1d0d('0x65')]['length']){_0x45f035=_0x1d0d('0x66')+_0x3942b6;_0x4dfb45[_0x1d0d('0x41')](_0x1d0d('0x67')+_0x45f035+'\x20LIKE\x20cm_contacts;');}var _0x3d499f=util[_0x1d0d('0x68')]('LOAD\x20DATA\x20LOCAL\x20INFILE\x20\x27%s\x27\x20INTO\x20TABLE\x20%s\x20CHARACTER\x20SET\x20UTF8\x20FIELDS\x20TERMINATED\x20BY\x20\x27,\x27\x20ENCLOSED\x20BY\x20\x27\x22\x27\x20LINES\x20TERMINATED\x20BY\x20\x27\x0a\x27\x20IGNORE\x201\x20ROWS\x20(%s)\x20SET\x20id\x20=\x20NULL,\x20ListId\x20=\x20%s,\x20CompanyId\x20=\x20%s,\x20createdAt\x20=\x20\x27%s\x27,\x20updatedAt\x20=\x20\x27%s\x27',_0x19b99c,_0x45f035,_0x1a6f7b,_0x18cd97[_0x1d0d('0x23')],_0x18cd97[_0x1d0d('0x37')]||null,NOW,NOW);if(_[_0x1d0d('0x69')](_0x24f077['scheduledat'])){_0x3d499f+=',\x20scheduledAt\x20=\x20NOW()';}_0x4dfb45[_0x1d0d('0x41')](_0x3d499f);if(_0x18cd97[_0x1d0d('0x65')]&&_0x18cd97[_0x1d0d('0x65')][_0x1d0d('0x51')]){_0x4dfb45[_0x1d0d('0x41')](insertCmContact(_0x18cd97[_0x1d0d('0x23')],_0x45f035,_0x18cd97[_0x1d0d('0x65')],_0x24f077));_0x4dfb45['push']('DROP\x20TABLE\x20'+_0x45f035+';');}_0x4dfb45[_0x1d0d('0x41')](insertCmHopper(_0x18cd97[_0x1d0d('0x23')],_0x1d0d('0x6a'),_0x1d0d('0x6b'),_0x1d0d('0x6c'),_0x2ec020));_0x4dfb45['push'](insertCmHopperBlack(_0x18cd97[_0x1d0d('0x23')],_0x1d0d('0x6d'),_0x1d0d('0x6b'),_0x1d0d('0x6c')));_0x4dfb45[_0x1d0d('0x41')](insertCmHopper(_0x18cd97['ListId'],_0x1d0d('0x6e'),_0x1d0d('0x6f'),_0x1d0d('0x70'),_0x2ec020));_0x4dfb45[_0x1d0d('0x41')](insertCmHopperBlack(_0x18cd97[_0x1d0d('0x23')],_0x1d0d('0x71'),_0x1d0d('0x6f'),_0x1d0d('0x70')));BPromise[_0x1d0d('0x72')](_0x4dfb45,handleQuery)[_0x1d0d('0x73')](function(_0x4dbc38){stats[_0x1d0d('0x74')]=!![];stats[_0x1d0d('0x75')]=_0x18cd97[_0x1d0d('0x65')]&&_0x18cd97['duplicates'][_0x1d0d('0x51')]?results[0x2][_0x1d0d('0x75')]:results[0x0][_0x1d0d('0x75')];socket[_0x1d0d('0x60')]('contact:import:'+_0x3942b6,stats);fs[_0x1d0d('0x76')](_0x3191ab);fs[_0x1d0d('0x76')](_0x19b99c);process[_0x1d0d('0x3f')](0x0);})[_0x1d0d('0x46')](function(_0x5cb9b4){logger[_0x1d0d('0x3e')](_0x5cb9b4[_0x1d0d('0x42')]);process[_0x1d0d('0x3f')](0x1);});}catch(_0x4ab86a){logger[_0x1d0d('0x3e')](_0x1d0d('0x77'),_0x4ab86a[_0x1d0d('0x42')]);process[_0x1d0d('0x3f')](0x1);}},'error':function(_0x52ba2e,_0x453cff,_0x23c8be,_0x47cc79){throw new Error(_0x47cc79);}});}function validate(){if(process[_0x1d0d('0x78')]&&process[_0x1d0d('0x78')][_0x1d0d('0x51')]<0x4){throw new Error('arguments\x20<filename>\x20<parameters>\x20<agents>');}var _0xf237db=path[_0x1d0d('0x12')](config[_0x1d0d('0x4b')],_0x1d0d('0x4c'),process[_0x1d0d('0x78')][0x2]);if(!fs[_0x1d0d('0x79')](_0xf237db)){throw new Error('file\x20doesn\x27t\x20exists');}var _0x1a81a4={};try{_0x1a81a4=JSON[_0x1d0d('0x50')](process['argv'][0x3]);if(!_0x1a81a4[_0x1d0d('0x7a')]){throw new Error(_0x1d0d('0x7b'));}if(!_0x1a81a4['binding'][_0x1d0d('0x10')]){throw new Error(_0x1d0d('0x7c'));}if(!_0x1a81a4[_0x1d0d('0x7a')][_0x1d0d('0x7d')]){throw new Error('firstName\x20is\x20mandatory');}var _0x385872=0x0;if(_0x1a81a4['binding'][_0x1d0d('0x27')]){_0x385872=0x1;}if(!_0x1a81a4[_0x1d0d('0x23')]){throw new Error('ListId\x20is\x20mandatory');}}catch(_0xc0c9d){throw new Error(_0x1d0d('0x7e'));}var _0x38433e=[];try{_0x38433e=_['map'](JSON[_0x1d0d('0x50')](process[_0x1d0d('0x78')][0x4]),'id');}catch(_0x2f470a){logger[_0x1d0d('0x3d')](_0x1d0d('0x7f'));}main(_0xf237db,_0x1a81a4,_0x38433e,_0x385872);}validate();process['on']('SIGINT',handleStop);process['on'](_0x1d0d('0x80'),handleUncaughtException);