Built motion from commit (unavailable).|2.5.26
[motion2.git] / server / components / import / cm / csv2.js
index 133b93c..923f5be 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xbbfd=['.id\x20=\x20','where','\x20=\x20','join','cm_contacts.phone','cm_contacts.updatedAt','insert','fromQuery','scheduledat','ListId','createdAt','priority','UserId','recallme','select','from','cm_contacts','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','cm_contacts.ListId','cm_contacts.createdAt','into','cm_hopper_black','updatedAt','.CmListId','ListId\x20=\x20?','toString','concat','keys',')\x20NOT\x20IN\x20?','fields','deletedAt\x20IS\x20NULL','id\x20IN\x20?','MIN(id)','min_id','group','info','Received\x20SIGINT','message','exit','errors','push','code','sequelize','spread','error','main','stringify','send','start','binding','socket_timestamp','root','server/files/tmp','.csv','writeFileSync','parse','length','rows','data','hasOwnProperty','trim','replace','isValid','isNaN','includes','agent\x20not\x20exists','email\x20wrong\x20format','YYYY-MM-DD','dateOfBirth\x20wrong\x20format\x20(YYYY-MM-DD)','firstName','\x20not\x20specified','contact:import:','abort','step','duplicates','cm_contacts_','CREATE\x20TABLE\x20','CompanyId','isNil',',\x20scheduledAt\x20=\x20NOW()','DROP\x20TABLE\x20','voice_queues_has_cm_lists','voice_queues','VoiceQueueId','campaigns_has_cm_lists','campaigns','CampaignId','campaigns_has_cm_blacklists','each','then','finish','affectedRows','emit','unlink','complete','argv','arguments\x20<filename>\x20<parameters>\x20<agents>','existsSync','file\x20doesn\x27t\x20exists','binding\x20doesn\x27t\x20exists','phone\x20is\x20mandatory','firstName\x20is\x20mandatory','ListId\x20is\x20mandatory','body\x20id\x20mandatory','map','No\x20agent\x20available','SIGINT','uncaughtException','path','lodash','papaparse','util','moment','squel','ioredis','../../../mysqldb','../../../config/environment','../../../config/logger','redis','defaults','socket.io-emitter','format','YYYY-MM-DD\x20HH:mm:ss','test','field','phone'];(function(_0x5b417b,_0x251759){var _0x9aa893=function(_0x529de6){while(--_0x529de6){_0x5b417b['push'](_0x5b417b['shift']());}};_0x9aa893(++_0x251759);}(_0xbbfd,0x72));var _0xdbbf=function(_0x7e2eb0,_0x17cd58){_0x7e2eb0=_0x7e2eb0-0x0;var _0xd92de4=_0xbbfd[_0x7e2eb0];return _0xd92de4;};'use strict';var fs=require('fs');var path=require(_0xdbbf('0x0'));var _=require(_0xdbbf('0x1'));var Papa=require(_0xdbbf('0x2'));var util=require(_0xdbbf('0x3'));var BPromise=require('bluebird');var moment=require(_0xdbbf('0x4'));var squel=require(_0xdbbf('0x5'));var Redis=require(_0xdbbf('0x6'));var db=require(_0xdbbf('0x7'))['db'];var config=require(_0xdbbf('0x8'));var logger=require(_0xdbbf('0x9'))('import');config[_0xdbbf('0xa')]=_[_0xdbbf('0xb')](config[_0xdbbf('0xa')],{'host':'localhost','port':0x18eb});var socket=require(_0xdbbf('0xc'))(new Redis(config[_0xdbbf('0xa')]));var stats={'finish':![],'errors':[],'rows':0x0,'affectedRows':0x0};var results=[];var stopped=![];var NOW=moment()[_0xdbbf('0xd')](_0xdbbf('0xe'));function isEmail(_0x1fddeb){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))*$/[_0xdbbf('0xf')](_0x1fddeb);}function selectNotIn(_0x575a50,_0x772b74,_0x57ed05,_0x186e80,_0x15863a){return squel['select']()[_0xdbbf('0x10')](_0xdbbf('0x11'))['from'](_0x186e80)['join'](_0x772b74,null,_0x772b74+_0xdbbf('0x12')+_0x186e80+'.'+_0x57ed05)[_0xdbbf('0x13')](_0x186e80+'.'+_0x57ed05+_0xdbbf('0x14')+_0x575a50+'.'+_0x57ed05)['where'](_0x772b74+'.dialCheckDuplicateType\x20IN\x20('+_0x15863a[_0xdbbf('0x15')]()+')');}function insertCmHopper(_0x218109,_0x5423ee,_0x529b1f,_0x5544fe,_0x4adc45){var _0x43e237=[_0xdbbf('0x16'),'cm_contacts.scheduledat','cm_contacts.id','cm_contacts.ListId',_0x5423ee+'.'+_0x5544fe,'cm_contacts.createdAt',_0xdbbf('0x17'),'cm_contacts.priority','cm_contacts.UserId','\x22'+_0x4adc45+'\x22'];return squel[_0xdbbf('0x18')]()['into']('cm_hopper')[_0xdbbf('0x19')]([_0xdbbf('0x11'),_0xdbbf('0x1a'),'ContactId',_0xdbbf('0x1b'),_0x5544fe,_0xdbbf('0x1c'),'updatedAt',_0xdbbf('0x1d'),_0xdbbf('0x1e'),_0xdbbf('0x1f')],squel[_0xdbbf('0x20')]()['fields'](_0x43e237)[_0xdbbf('0x21')](_0x5423ee)[_0xdbbf('0x15')](_0xdbbf('0x22'),null,_0xdbbf('0x23')+_0x5423ee+'.CmListId')[_0xdbbf('0x15')](_0x529b1f,null,_0x529b1f+_0xdbbf('0x12')+_0x5423ee+'.'+_0x5544fe)[_0xdbbf('0x13')](_0x5423ee+_0xdbbf('0x24'),_0x218109)[_0xdbbf('0x13')](_0xdbbf('0x25'),NOW)[_0xdbbf('0x13')](_0xdbbf('0x26'),selectNotIn(_0x5423ee,_0x529b1f,_0x5544fe,_0xdbbf('0x27'),[_0xdbbf('0x28'),_0xdbbf('0x29')]))[_0xdbbf('0x13')](_0xdbbf('0x26'),selectNotIn(_0x5423ee,_0x529b1f,_0x5544fe,_0xdbbf('0x27'),['\x22always\x22'])))['toString']();}function insertCmHopperBlack(_0x420ff6,_0x103faa,_0x55966c,_0x5e73c0){var _0x2194ed=[_0xdbbf('0x16'),'cm_contacts.id',_0xdbbf('0x2a'),_0x103faa+'.'+_0x5e73c0,_0xdbbf('0x2b'),_0xdbbf('0x17')];return squel['insert']()[_0xdbbf('0x2c')](_0xdbbf('0x2d'))[_0xdbbf('0x19')]([_0xdbbf('0x11'),'ContactId','ListId',_0x5e73c0,_0xdbbf('0x1c'),_0xdbbf('0x2e')],squel[_0xdbbf('0x20')]()['fields'](_0x2194ed)[_0xdbbf('0x21')](_0x103faa)[_0xdbbf('0x15')](_0xdbbf('0x22'),null,_0xdbbf('0x23')+_0x103faa+_0xdbbf('0x2f'))[_0xdbbf('0x15')](_0x55966c,null,_0x55966c+'.id\x20=\x20'+_0x103faa+'.'+_0x5e73c0)[_0xdbbf('0x13')](_0x103faa+'.CmListId\x20=\x20?',_0x420ff6)[_0xdbbf('0x13')]('cm_contacts.createdAt\x20=\x20?',NOW)[_0xdbbf('0x13')]('cm_contacts.phone\x20NOT\x20IN\x20(?)',squel['select']()[_0xdbbf('0x10')](_0xdbbf('0x11'))[_0xdbbf('0x21')](_0xdbbf('0x2d'))['where'](_0xdbbf('0x30'),_0x420ff6)[_0xdbbf('0x13')](_0x5e73c0+'\x20=\x20?',_0x103faa+'.'+_0x5e73c0)))[_0xdbbf('0x31')]();}function insertCmContact(_0x2c3ae,_0x293184,_0x51a92f,_0x413b83){var _0x459fd8=_[_0xdbbf('0x32')](_[_0xdbbf('0x33')](_0x413b83),[_0xdbbf('0x1b'),'CompanyId','createdAt','updatedAt']);return squel['insert']()[_0xdbbf('0x2c')](_0xdbbf('0x22'))[_0xdbbf('0x19')](_0x459fd8,squel[_0xdbbf('0x20')]()['fields'](_0x459fd8)[_0xdbbf('0x21')](_0x293184)[_0xdbbf('0x13')]('('+_0x51a92f[_0xdbbf('0x15')](',')+_0xdbbf('0x34'),squel[_0xdbbf('0x20')]()[_0xdbbf('0x35')](_0x51a92f)[_0xdbbf('0x21')](_0xdbbf('0x22'))['where'](_0xdbbf('0x30'),_0x2c3ae)[_0xdbbf('0x13')](_0xdbbf('0x36')))[_0xdbbf('0x13')](_0xdbbf('0x37'),squel[_0xdbbf('0x20')]()[_0xdbbf('0x10')](_0xdbbf('0x38'),_0xdbbf('0x39'))[_0xdbbf('0x21')](_0x293184)[_0xdbbf('0x3a')](_0x51a92f[_0xdbbf('0x15')](','))))['toString']();}function handleStop(){logger[_0xdbbf('0x3b')](_0xdbbf('0x3c'));stopped=!![];}function handleUncaughtException(_0x3c94cb){logger['error'](_0x3c94cb[_0xdbbf('0x3d')]);process[_0xdbbf('0x3e')](0x1);}function handleError(_0x4e7ea2,_0x32cdb1){stats[_0xdbbf('0x3f')][_0xdbbf('0x40')]({'name':_0x32cdb1[_0xdbbf('0x41')],'message':_0x32cdb1[_0xdbbf('0x3d')],'row':_0x4e7ea2});}function handleQuery(_0x189573){logger['info'](_0x189573);return db[_0xdbbf('0x42')]['query'](_0x189573)[_0xdbbf('0x43')](function(_0x1af7de){results[_0xdbbf('0x40')](_0x1af7de);})['catch'](function(_0x480841){logger[_0xdbbf('0x44')](_0x480841[_0xdbbf('0x3d')]);});}function main(_0x42b47e,_0x573b74,_0x316f1d,_0x2a399c){logger[_0xdbbf('0x3b')](_0xdbbf('0x45'),_0x42b47e,JSON[_0xdbbf('0x46')](_0x573b74));process[_0xdbbf('0x47')](_0xdbbf('0x48'));var _0x12892e=_0x573b74[_0xdbbf('0x49')];var _0x70eab3=_0x573b74[_0xdbbf('0x4a')];var _0x1b0198=path[_0xdbbf('0x15')](config[_0xdbbf('0x4b')],_0xdbbf('0x4c'),_0x70eab3+_0xdbbf('0x4d'));var _0x3a3f06=_[_0xdbbf('0x33')](_0x12892e)[_0xdbbf('0x15')]();logger[_0xdbbf('0x3b')]('header',_0x3a3f06);fs[_0xdbbf('0x4e')](_0x1b0198,_0x3a3f06+'\x0a');Papa[_0xdbbf('0x4f')](fs['createReadStream'](_0x42b47e),{'header':!![],'skipEmptyLines':!![],'step':function(_0x5a0ebd,_0x40fd03){try{for(var _0xaa2954=0x0,_0x40ca4a=[];_0xaa2954<_0x5a0ebd['data'][_0xdbbf('0x50')];_0xaa2954++){stats[_0xdbbf('0x51')]+=0x1;if(_0x5a0ebd['errors'][_0xaa2954]){handleError(_0x5a0ebd[_0xdbbf('0x52')][_0xaa2954],_0x5a0ebd[_0xdbbf('0x3f')][_0xaa2954]);}else{var _0x461136=[];for(var _0x5dbc0c in _0x12892e){if(_0x12892e[_0xdbbf('0x53')](_0x5dbc0c)){if(_0x5a0ebd[_0xdbbf('0x52')][_0xaa2954][_0x12892e[_0x5dbc0c]]){var _0x138a00=_[_0xdbbf('0x54')](_0x5a0ebd[_0xdbbf('0x52')][_0xaa2954][_0x12892e[_0x5dbc0c]][_0xdbbf('0x55')](/"/g,'\x27'));switch(_0x5dbc0c){case _0xdbbf('0x1a'):var _0x3263d1=moment(_0x138a00,_0xdbbf('0xe'),!![]);if(_0x3263d1[_0xdbbf('0x56')]()){_0x40ca4a[_0xdbbf('0x40')]('\x22'+_0x138a00+'\x22');}else{_0x461136[_0xdbbf('0x40')]('scheduledat\x20wrong\x20format\x20(YYYY-MM-DD\x20HH:mm:ss)');}break;case _0xdbbf('0x1d'):var _0x4d9805=parseInt(_0x138a00);_0x138a00=_[_0xdbbf('0x57')](_0x4d9805)||_0x4d9805<0x0||_0x4d9805>0x4?_0x2a399c?0x3:0x2:_0x4d9805;_0x40ca4a[_0xdbbf('0x40')]('\x22'+_0x138a00+'\x22');break;case'UserId':var _0x384b24=parseInt(_0x138a00);if(_['isNumber'](_0x384b24)&&_[_0xdbbf('0x58')](_0x316f1d,_0x384b24)){_0x40ca4a['push']('\x22'+_0x384b24+'\x22');}else{_0x461136[_0xdbbf('0x40')](_0xdbbf('0x59'));}break;case'email':if(isEmail(_0x138a00)){_0x40ca4a[_0xdbbf('0x40')]('\x22'+_0x138a00+'\x22');}else{_0x461136[_0xdbbf('0x40')](_0xdbbf('0x5a'));}break;case'dateOfBirth':var _0x5edb5c=moment(_0x138a00,_0xdbbf('0x5b'),!![]);if(_0x5edb5c[_0xdbbf('0x56')]()){_0x40ca4a['push']('\x22'+_0x138a00+'\x22');}else{_0x461136[_0xdbbf('0x40')](_0xdbbf('0x5c'));}break;default:_0x40ca4a[_0xdbbf('0x40')]('\x22'+_0x138a00+'\x22');}}else{switch(_0x5dbc0c){case _0xdbbf('0x5d'):case _0xdbbf('0x11'):_0x461136[_0xdbbf('0x40')](_0x5dbc0c+_0xdbbf('0x5e'));break;default:_0x40ca4a[_0xdbbf('0x40')]('\x22\x22');}}}}if(_0x461136[_0xdbbf('0x50')]){handleError(_0x5a0ebd[_0xdbbf('0x52')][_0xaa2954],{'code':'SystemRow','message':_0x461136['join']()});}else{fs['appendFileSync'](_0x1b0198,_0x40ca4a[_0xdbbf('0x15')]()+'\x0a');}_0x40ca4a=[];}if(!(stats[_0xdbbf('0x51')]%0xc8)){socket['emit'](_0xdbbf('0x5f')+_0x70eab3,stats);stats['errors']=[];}}if(stopped){logger['info']('Abort\x20parser');_0x40fd03[_0xdbbf('0x60')]();}}catch(_0x357186){handleError(_0x5a0ebd[_0xdbbf('0x52')][_0xaa2954],{'code':'SystemError','message':_0x357186[_0xdbbf('0x3d')]});logger[_0xdbbf('0x44')](_0xdbbf('0x61'),_0x357186[_0xdbbf('0x3d')]);}},'complete':function(){try{var _0x490674=[];var _0x11295f=_0xdbbf('0x22');if(_0x573b74['duplicates']&&_0x573b74[_0xdbbf('0x62')]['length']){_0x11295f=_0xdbbf('0x63')+_0x70eab3;_0x490674[_0xdbbf('0x40')](_0xdbbf('0x64')+_0x11295f+'\x20LIKE\x20cm_contacts;');}var _0x5653eb=util[_0xdbbf('0xd')]('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',_0x1b0198,_0x11295f,_0x3a3f06,_0x573b74[_0xdbbf('0x1b')],_0x573b74[_0xdbbf('0x65')]||null,NOW,NOW);if(_[_0xdbbf('0x66')](_0x12892e[_0xdbbf('0x1a')])){_0x5653eb+=_0xdbbf('0x67');}_0x490674[_0xdbbf('0x40')](_0x5653eb);if(_0x573b74[_0xdbbf('0x62')]&&_0x573b74[_0xdbbf('0x62')]['length']){_0x490674[_0xdbbf('0x40')](insertCmContact(_0x573b74[_0xdbbf('0x1b')],_0x11295f,_0x573b74[_0xdbbf('0x62')],_0x12892e));_0x490674[_0xdbbf('0x40')](_0xdbbf('0x68')+_0x11295f+';');}_0x490674[_0xdbbf('0x40')](insertCmHopper(_0x573b74[_0xdbbf('0x1b')],_0xdbbf('0x69'),_0xdbbf('0x6a'),_0xdbbf('0x6b'),_0x2a399c));_0x490674[_0xdbbf('0x40')](insertCmHopperBlack(_0x573b74[_0xdbbf('0x1b')],'voice_queues_has_cm_blacklists',_0xdbbf('0x6a'),'VoiceQueueId'));_0x490674[_0xdbbf('0x40')](insertCmHopper(_0x573b74[_0xdbbf('0x1b')],_0xdbbf('0x6c'),_0xdbbf('0x6d'),_0xdbbf('0x6e'),_0x2a399c));_0x490674[_0xdbbf('0x40')](insertCmHopperBlack(_0x573b74['ListId'],_0xdbbf('0x6f'),_0xdbbf('0x6d'),_0xdbbf('0x6e')));BPromise[_0xdbbf('0x70')](_0x490674,handleQuery)[_0xdbbf('0x71')](function(_0x524252){stats[_0xdbbf('0x72')]=!![];stats[_0xdbbf('0x73')]=_0x573b74[_0xdbbf('0x62')]&&_0x573b74[_0xdbbf('0x62')][_0xdbbf('0x50')]?results[0x2]['affectedRows']:results[0x0][_0xdbbf('0x73')];socket[_0xdbbf('0x74')]('contact:import:'+_0x70eab3,stats);fs[_0xdbbf('0x75')](_0x42b47e);fs[_0xdbbf('0x75')](_0x1b0198);process[_0xdbbf('0x3e')](0x0);})['catch'](function(_0x142552){logger[_0xdbbf('0x44')](_0x142552['message']);process[_0xdbbf('0x3e')](0x1);});}catch(_0x5cbe32){logger[_0xdbbf('0x44')](_0xdbbf('0x76'),_0x5cbe32[_0xdbbf('0x3d')]);process['exit'](0x1);}},'error':function(_0x17cb3f,_0x4cf097,_0x3b18fb,_0x4db598){throw new Error(_0x4db598);}});}function validate(){if(process['argv']&&process[_0xdbbf('0x77')][_0xdbbf('0x50')]<0x4){throw new Error(_0xdbbf('0x78'));}var _0x3ca791=path[_0xdbbf('0x15')](config[_0xdbbf('0x4b')],_0xdbbf('0x4c'),process[_0xdbbf('0x77')][0x2]);if(!fs[_0xdbbf('0x79')](_0x3ca791)){throw new Error(_0xdbbf('0x7a'));}var _0x445a85={};try{_0x445a85=JSON[_0xdbbf('0x4f')](process['argv'][0x3]);if(!_0x445a85[_0xdbbf('0x49')]){throw new Error(_0xdbbf('0x7b'));}if(!_0x445a85[_0xdbbf('0x49')]['phone']){throw new Error(_0xdbbf('0x7c'));}if(!_0x445a85[_0xdbbf('0x49')][_0xdbbf('0x5d')]){throw new Error(_0xdbbf('0x7d'));}var _0x4d20e4=0x0;if(_0x445a85[_0xdbbf('0x49')][_0xdbbf('0x1e')]){_0x4d20e4=0x1;}if(!_0x445a85['ListId']){throw new Error(_0xdbbf('0x7e'));}}catch(_0x44f943){throw new Error(_0xdbbf('0x7f'));}var _0x8046d7=[];try{_0x8046d7=_[_0xdbbf('0x80')](JSON[_0xdbbf('0x4f')](process[_0xdbbf('0x77')][0x4]),'id');}catch(_0xd83574){logger['info'](_0xdbbf('0x81'));}main(_0x3ca791,_0x445a85,_0x8046d7,_0x4d20e4);}validate();process['on'](_0xdbbf('0x82'),handleStop);process['on'](_0xdbbf('0x83'),handleUncaughtException);
\ No newline at end of file
+var _0x1885=['phone','scheduledat','ContactId','ListId','createdAt','priority','recallme','select','cm_contacts','cm_contacts.createdAt\x20=\x20?','cm_contacts.phone\x20NOT\x20IN\x20(?)','\x22always\x22','\x22onlyIfOpen\x22','into','cm_hopper_black','updatedAt','fields','cm_contacts.ListId\x20=\x20','.CmListId\x20=\x20?','ListId\x20=\x20?','\x20=\x20?','toString','concat','keys','CompanyId','id\x20IN\x20?','field','MIN(id)','min_id','group','info','Received\x20SIGINT','error','message','exit','errors','push','code','sequelize','spread','catch','main','stringify','send','start','socket_timestamp','.csv','header','writeFileSync','parse','createReadStream','length','rows','hasOwnProperty','data','trim','replace','isValid','scheduledat\x20wrong\x20format\x20(YYYY-MM-DD\x20HH:mm:ss)','isNaN','UserId','isNumber','includes','agent\x20not\x20exists','email\x20wrong\x20format','dateOfBirth\x20wrong\x20format\x20(YYYY-MM-DD)','firstName','\x20not\x20specified','SystemRow','appendFileSync','emit','contact:import:','Abort\x20parser','abort','SystemError','duplicates','cm_contacts_','CREATE\x20TABLE\x20','\x20LIKE\x20cm_contacts;','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','isNil',',\x20scheduledAt\x20=\x20NOW()','DROP\x20TABLE\x20','voice_queues_has_cm_lists','voice_queues','VoiceQueueId','voice_queues_has_cm_blacklists','campaigns_has_cm_lists','campaigns','campaigns_has_cm_blacklists','CampaignId','then','finish','affectedRows','unlink','argv','arguments\x20<filename>\x20<parameters>\x20<agents>','root','existsSync','binding','phone\x20is\x20mandatory','firstName\x20is\x20mandatory','ListId\x20is\x20mandatory','body\x20id\x20mandatory','No\x20agent\x20available','uncaughtException','path','lodash','papaparse','util','ioredis','../../../mysqldb','../../../config/environment','../../../config/logger','import','redis','defaults','socket.io-emitter','YYYY-MM-DD\x20HH:mm:ss','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.UserId','insert','cm_hopper','fromQuery'];(function(_0x11268b,_0x323f6c){var _0x189dd1=function(_0x101417){while(--_0x101417){_0x11268b['push'](_0x11268b['shift']());}};_0x189dd1(++_0x323f6c);}(_0x1885,0xf0));var _0x5188=function(_0x5520b4,_0x4c9f22){_0x5520b4=_0x5520b4-0x0;var _0x119723=_0x1885[_0x5520b4];return _0x119723;};'use strict';var fs=require('fs');var path=require(_0x5188('0x0'));var _=require(_0x5188('0x1'));var Papa=require(_0x5188('0x2'));var util=require(_0x5188('0x3'));var BPromise=require('bluebird');var moment=require('moment');var squel=require('squel');var Redis=require(_0x5188('0x4'));var db=require(_0x5188('0x5'))['db'];var config=require(_0x5188('0x6'));var logger=require(_0x5188('0x7'))(_0x5188('0x8'));config[_0x5188('0x9')]=_[_0x5188('0xa')](config[_0x5188('0x9')],{'host':'localhost','port':0x18eb});var socket=require(_0x5188('0xb'))(new Redis(config[_0x5188('0x9')]));var stats={'finish':![],'errors':[],'rows':0x0,'affectedRows':0x0};var results=[];var stopped=![];var NOW=moment()['format'](_0x5188('0xc'));function isEmail(_0x208a5f){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))*$/['test'](_0x208a5f);}function selectNotIn(_0x4d9fb4,_0x57c060,_0x224187,_0xdf50cb,_0x92698a){return squel['select']()['field']('phone')[_0x5188('0xd')](_0xdf50cb)[_0x5188('0xe')](_0x57c060,null,_0x57c060+_0x5188('0xf')+_0xdf50cb+'.'+_0x224187)[_0x5188('0x10')](_0xdf50cb+'.'+_0x224187+_0x5188('0x11')+_0x4d9fb4+'.'+_0x224187)[_0x5188('0x10')](_0x57c060+_0x5188('0x12')+_0x92698a['join']()+')');}function insertCmHopper(_0x553afb,_0x11936c,_0x4ab41c,_0x21af9f,_0x40d778){var _0x2f51db=['cm_contacts.phone',_0x5188('0x13'),_0x5188('0x14'),_0x5188('0x15'),_0x11936c+'.'+_0x21af9f,_0x5188('0x16'),_0x5188('0x17'),'cm_contacts.priority',_0x5188('0x18'),'\x22'+_0x40d778+'\x22'];return squel[_0x5188('0x19')]()['into'](_0x5188('0x1a'))[_0x5188('0x1b')]([_0x5188('0x1c'),_0x5188('0x1d'),_0x5188('0x1e'),_0x5188('0x1f'),_0x21af9f,_0x5188('0x20'),'updatedAt',_0x5188('0x21'),'UserId',_0x5188('0x22')],squel[_0x5188('0x23')]()['fields'](_0x2f51db)[_0x5188('0xd')](_0x11936c)[_0x5188('0xe')](_0x5188('0x24'),null,'cm_contacts.ListId\x20=\x20'+_0x11936c+'.CmListId')[_0x5188('0xe')](_0x4ab41c,null,_0x4ab41c+_0x5188('0xf')+_0x11936c+'.'+_0x21af9f)[_0x5188('0x10')](_0x11936c+'.CmListId\x20=\x20?',_0x553afb)[_0x5188('0x10')](_0x5188('0x25'),NOW)['where'](_0x5188('0x26'),selectNotIn(_0x11936c,_0x4ab41c,_0x21af9f,_0x5188('0x1a'),[_0x5188('0x27'),_0x5188('0x28')]))['where'](_0x5188('0x26'),selectNotIn(_0x11936c,_0x4ab41c,_0x21af9f,_0x5188('0x1a'),['\x22always\x22'])))['toString']();}function insertCmHopperBlack(_0x85771f,_0x1d7166,_0x3f565f,_0x39875c){var _0x33b27c=['cm_contacts.phone',_0x5188('0x14'),_0x5188('0x15'),_0x1d7166+'.'+_0x39875c,_0x5188('0x16'),_0x5188('0x17')];return squel[_0x5188('0x19')]()[_0x5188('0x29')](_0x5188('0x2a'))[_0x5188('0x1b')](['phone',_0x5188('0x1e'),'ListId',_0x39875c,_0x5188('0x20'),_0x5188('0x2b')],squel[_0x5188('0x23')]()[_0x5188('0x2c')](_0x33b27c)[_0x5188('0xd')](_0x1d7166)[_0x5188('0xe')](_0x5188('0x24'),null,_0x5188('0x2d')+_0x1d7166+'.CmListId')[_0x5188('0xe')](_0x3f565f,null,_0x3f565f+_0x5188('0xf')+_0x1d7166+'.'+_0x39875c)[_0x5188('0x10')](_0x1d7166+_0x5188('0x2e'),_0x85771f)[_0x5188('0x10')]('cm_contacts.createdAt\x20=\x20?',NOW)[_0x5188('0x10')](_0x5188('0x26'),squel[_0x5188('0x23')]()['field'](_0x5188('0x1c'))[_0x5188('0xd')](_0x5188('0x2a'))[_0x5188('0x10')](_0x5188('0x2f'),_0x85771f)[_0x5188('0x10')](_0x39875c+_0x5188('0x30'),_0x1d7166+'.'+_0x39875c)))[_0x5188('0x31')]();}function insertCmContact(_0x5a0afa,_0x1df169,_0x159055,_0x28f732){var _0x3175f7=_[_0x5188('0x32')](_[_0x5188('0x33')](_0x28f732),[_0x5188('0x1f'),_0x5188('0x34'),_0x5188('0x20'),_0x5188('0x2b')]);return squel[_0x5188('0x19')]()['into'](_0x5188('0x24'))[_0x5188('0x1b')](_0x3175f7,squel[_0x5188('0x23')]()[_0x5188('0x2c')](_0x3175f7)[_0x5188('0xd')](_0x1df169)[_0x5188('0x10')]('('+_0x159055[_0x5188('0xe')](',')+')\x20NOT\x20IN\x20?',squel[_0x5188('0x23')]()[_0x5188('0x2c')](_0x159055)[_0x5188('0xd')]('cm_contacts')[_0x5188('0x10')](_0x5188('0x2f'),_0x5a0afa)[_0x5188('0x10')]('deletedAt\x20IS\x20NULL'))[_0x5188('0x10')](_0x5188('0x35'),squel['select']()[_0x5188('0x36')](_0x5188('0x37'),_0x5188('0x38'))[_0x5188('0xd')](_0x1df169)[_0x5188('0x39')](_0x159055[_0x5188('0xe')](','))))[_0x5188('0x31')]();}function handleStop(){logger[_0x5188('0x3a')](_0x5188('0x3b'));stopped=!![];}function handleUncaughtException(_0xab7d40){logger[_0x5188('0x3c')](_0xab7d40[_0x5188('0x3d')]);process[_0x5188('0x3e')](0x1);}function handleError(_0xa6a308,_0x34d7d9){stats[_0x5188('0x3f')][_0x5188('0x40')]({'name':_0x34d7d9[_0x5188('0x41')],'message':_0x34d7d9[_0x5188('0x3d')],'row':_0xa6a308});}function handleQuery(_0x1e87ed){logger[_0x5188('0x3a')](_0x1e87ed);return db[_0x5188('0x42')]['query'](_0x1e87ed)[_0x5188('0x43')](function(_0x1f42f2){results['push'](_0x1f42f2);})[_0x5188('0x44')](function(_0x3616ae){logger[_0x5188('0x3c')](_0x3616ae['message']);});}function main(_0xcb2386,_0x5248db,_0x320986,_0x3ff04b){logger['info'](_0x5188('0x45'),_0xcb2386,JSON[_0x5188('0x46')](_0x5248db));process[_0x5188('0x47')](_0x5188('0x48'));var _0x3e27c6=_0x5248db['binding'];var _0x2a80de=_0x5248db[_0x5188('0x49')];var _0x3d3901=path[_0x5188('0xe')](config['root'],'server/files/tmp',_0x2a80de+_0x5188('0x4a'));var _0x14463a=_['keys'](_0x3e27c6)[_0x5188('0xe')]();logger[_0x5188('0x3a')](_0x5188('0x4b'),_0x14463a);fs[_0x5188('0x4c')](_0x3d3901,_0x14463a+'\x0a');Papa[_0x5188('0x4d')](fs[_0x5188('0x4e')](_0xcb2386),{'header':!![],'skipEmptyLines':!![],'step':function(_0x6d7e5a,_0x20bd02){try{for(var _0x290ecc=0x0,_0x55e534=[];_0x290ecc<_0x6d7e5a['data'][_0x5188('0x4f')];_0x290ecc++){stats[_0x5188('0x50')]+=0x1;if(_0x6d7e5a[_0x5188('0x3f')][_0x290ecc]){handleError(_0x6d7e5a['data'][_0x290ecc],_0x6d7e5a['errors'][_0x290ecc]);}else{var _0x2ed9d7=[];for(var _0x3bad70 in _0x3e27c6){if(_0x3e27c6[_0x5188('0x51')](_0x3bad70)){if(_0x6d7e5a[_0x5188('0x52')][_0x290ecc][_0x3e27c6[_0x3bad70]]){var _0x182259=_[_0x5188('0x53')](_0x6d7e5a[_0x5188('0x52')][_0x290ecc][_0x3e27c6[_0x3bad70]][_0x5188('0x54')](/"/g,'\x27'));switch(_0x3bad70){case'scheduledat':var _0x5474b9=moment(_0x182259,'YYYY-MM-DD\x20HH:mm:ss',!![]);if(_0x5474b9[_0x5188('0x55')]()){_0x55e534['push']('\x22'+_0x182259+'\x22');}else{_0x2ed9d7['push'](_0x5188('0x56'));}break;case _0x5188('0x21'):var _0x256a8e=parseInt(_0x182259);_0x182259=_[_0x5188('0x57')](_0x256a8e)||_0x256a8e<0x0||_0x256a8e>0x4?_0x3ff04b?0x3:0x2:_0x256a8e;_0x55e534['push']('\x22'+_0x182259+'\x22');break;case _0x5188('0x58'):var _0x226bcd=parseInt(_0x182259);if(_[_0x5188('0x59')](_0x226bcd)&&_[_0x5188('0x5a')](_0x320986,_0x226bcd)){_0x55e534[_0x5188('0x40')]('\x22'+_0x226bcd+'\x22');}else{_0x2ed9d7[_0x5188('0x40')](_0x5188('0x5b'));}break;case'email':if(isEmail(_0x182259)){_0x55e534['push']('\x22'+_0x182259+'\x22');}else{_0x2ed9d7['push'](_0x5188('0x5c'));}break;case'dateOfBirth':var _0x1a696c=moment(_0x182259,'YYYY-MM-DD',!![]);if(_0x1a696c[_0x5188('0x55')]()){_0x55e534['push']('\x22'+_0x182259+'\x22');}else{_0x2ed9d7[_0x5188('0x40')](_0x5188('0x5d'));}break;default:_0x55e534[_0x5188('0x40')]('\x22'+_0x182259+'\x22');}}else{switch(_0x3bad70){case _0x5188('0x5e'):case'phone':_0x2ed9d7[_0x5188('0x40')](_0x3bad70+_0x5188('0x5f'));break;default:_0x55e534[_0x5188('0x40')]('\x22\x22');}}}}if(_0x2ed9d7['length']){handleError(_0x6d7e5a[_0x5188('0x52')][_0x290ecc],{'code':_0x5188('0x60'),'message':_0x2ed9d7[_0x5188('0xe')]()});}else{fs[_0x5188('0x61')](_0x3d3901,_0x55e534[_0x5188('0xe')]()+'\x0a');}_0x55e534=[];}if(!(stats[_0x5188('0x50')]%0xc8)){socket[_0x5188('0x62')](_0x5188('0x63')+_0x2a80de,stats);stats[_0x5188('0x3f')]=[];}}if(stopped){logger[_0x5188('0x3a')](_0x5188('0x64'));_0x20bd02[_0x5188('0x65')]();}}catch(_0x121481){handleError(_0x6d7e5a[_0x5188('0x52')][_0x290ecc],{'code':_0x5188('0x66'),'message':_0x121481['message']});logger[_0x5188('0x3c')]('step',_0x121481[_0x5188('0x3d')]);}},'complete':function(){try{var _0x3b76d0=[];var _0x53ab46='cm_contacts';if(_0x5248db[_0x5188('0x67')]&&_0x5248db['duplicates'][_0x5188('0x4f')]){_0x53ab46=_0x5188('0x68')+_0x2a80de;_0x3b76d0[_0x5188('0x40')](_0x5188('0x69')+_0x53ab46+_0x5188('0x6a'));}var _0x187be2=util['format'](_0x5188('0x6b'),_0x3d3901,_0x53ab46,_0x14463a,_0x5248db[_0x5188('0x1f')],_0x5248db[_0x5188('0x34')]||null,NOW,NOW);if(_[_0x5188('0x6c')](_0x3e27c6[_0x5188('0x1d')])){_0x187be2+=_0x5188('0x6d');}_0x3b76d0[_0x5188('0x40')](_0x187be2);if(_0x5248db[_0x5188('0x67')]&&_0x5248db[_0x5188('0x67')][_0x5188('0x4f')]){_0x3b76d0[_0x5188('0x40')](insertCmContact(_0x5248db[_0x5188('0x1f')],_0x53ab46,_0x5248db[_0x5188('0x67')],_0x3e27c6));_0x3b76d0[_0x5188('0x40')](_0x5188('0x6e')+_0x53ab46+';');}_0x3b76d0[_0x5188('0x40')](insertCmHopper(_0x5248db['ListId'],_0x5188('0x6f'),_0x5188('0x70'),_0x5188('0x71'),_0x3ff04b));_0x3b76d0[_0x5188('0x40')](insertCmHopperBlack(_0x5248db['ListId'],_0x5188('0x72'),_0x5188('0x70'),'VoiceQueueId'));_0x3b76d0['push'](insertCmHopper(_0x5248db[_0x5188('0x1f')],_0x5188('0x73'),_0x5188('0x74'),'CampaignId',_0x3ff04b));_0x3b76d0[_0x5188('0x40')](insertCmHopperBlack(_0x5248db[_0x5188('0x1f')],_0x5188('0x75'),_0x5188('0x74'),_0x5188('0x76')));BPromise['each'](_0x3b76d0,handleQuery)[_0x5188('0x77')](function(_0x5cd08a){stats[_0x5188('0x78')]=!![];stats[_0x5188('0x79')]=_0x5248db[_0x5188('0x67')]&&_0x5248db[_0x5188('0x67')][_0x5188('0x4f')]?results[0x2][_0x5188('0x79')]:results[0x0][_0x5188('0x79')];socket[_0x5188('0x62')]('contact:import:'+_0x2a80de,stats);fs[_0x5188('0x7a')](_0xcb2386);fs[_0x5188('0x7a')](_0x3d3901);process[_0x5188('0x3e')](0x0);})['catch'](function(_0x38e1d9){logger['error'](_0x38e1d9['message']);process[_0x5188('0x3e')](0x1);});}catch(_0x4ea61e){logger[_0x5188('0x3c')]('complete',_0x4ea61e[_0x5188('0x3d')]);process[_0x5188('0x3e')](0x1);}},'error':function(_0x431c71,_0x79c576,_0x593756,_0x5e3598){throw new Error(_0x5e3598);}});}function validate(){if(process['argv']&&process[_0x5188('0x7b')]['length']<0x4){throw new Error(_0x5188('0x7c'));}var _0x34d014=path[_0x5188('0xe')](config[_0x5188('0x7d')],'server/files/tmp',process[_0x5188('0x7b')][0x2]);if(!fs[_0x5188('0x7e')](_0x34d014)){throw new Error('file\x20doesn\x27t\x20exists');}var _0x3129b7={};try{_0x3129b7=JSON['parse'](process[_0x5188('0x7b')][0x3]);if(!_0x3129b7[_0x5188('0x7f')]){throw new Error('binding\x20doesn\x27t\x20exists');}if(!_0x3129b7['binding'][_0x5188('0x1c')]){throw new Error(_0x5188('0x80'));}if(!_0x3129b7['binding'][_0x5188('0x5e')]){throw new Error(_0x5188('0x81'));}var _0x57e15b=0x0;if(_0x3129b7['binding'][_0x5188('0x58')]){_0x57e15b=0x1;}if(!_0x3129b7[_0x5188('0x1f')]){throw new Error(_0x5188('0x82'));}}catch(_0xd5bc18){throw new Error(_0x5188('0x83'));}var _0x22de7d=[];try{_0x22de7d=_['map'](JSON[_0x5188('0x4d')](process[_0x5188('0x7b')][0x4]),'id');}catch(_0x1da71f){logger['info'](_0x5188('0x84'));}main(_0x34d014,_0x3129b7,_0x22de7d,_0x57e15b);}validate();process['on']('SIGINT',handleStop);process['on'](_0x5188('0x85'),handleUncaughtException);
\ No newline at end of file