Esempio n. 1
0
 def send_message(self,
                  params,
                  callback=None,
                  keepOpen=False,
                  backToMain=False):
     body = params['message']
     connId = params['connId']
     url = params['url']
     if not connId:
         self.sel.loadPage(url)
         topcard = self.sel.waitShowElement(self.PROFILE_CONTENT)
         connId = LinkedinHelper.get_conn_id(self.sel.getCode())
     if connId:
         msgUrl = self.CHAT_URL + connId
         self.sel.loadPage(msgUrl)
         textarea = self.sel.waitShowElement(self.TEXTBOX_MESSAGE)
         try:
             textarea.send_keys(body)
             textarea.send_keys('\n\r')
             textarea.send_keys('\n\r')
         except:
             pass
             # LogHelper.log(sys.exc_info())
         time.sleep(0.5)
         exit = 'OK'
     else:
         exit = 'User not found'
     LogHelper.log(exit)
     if callback:
         callback(params)
     if not keepOpen:
         self.sel.close()
     elif backToMain:
         self.sel.loadPage(self.SITE_URL)
Esempio n. 2
0
 def getCookies(self):
     cookies = {}
     try:
         cookies = self.driver.get_cookies()
     except:
         LogHelper.log(sys.exc_info())
     return cookies
 def run_queue(self, params, callback):
     LogHelper.log('EXECUTING ' + self.__class__.__name__, True)
     LogHelper.log('INPUT ' + self.__class__.__name__ + ' ' + str(params),
                   True)
     output = {}
     output["mod2out"] = params["mod1out"] * 2
     self.pop(params, output, callback)
 def run_queue(self, params, callback):
     LogHelper.log('EXECUTING ' + self.__class__.__name__, True)
     LogHelper.log('INPUT ' + self.__class__.__name__ + ' ' + str(params), True)
     filem=open(params["filename"],'r')
     reader=csv.reader(filem)
     for row in reader:
         for value in row:
             self.pop(params, {"mod1out": value}, callback)
	def insert_one(self, params, table=None):
		result = False
		try:
			col = self.get_collection(table)
			result = col.insert_one(params).inserted_id
		except:
			LogHelper.log(sys.exc_info())
		return result
	def update_one(self, where, params, table=None):
		result = False
		try:
			col = self.get_collection(table)
			result = col.update_one(where, {"$set": params}).modified_count
		except:
			LogHelper.log(sys.exc_info())
		return result		
	def delete_one(self, where, table=None):
		result = False
		try:
			col = self.get_collection(table)
			result = col.delete_one(where).deleted_count
		except:
			LogHelper.log(sys.exc_info())
		return result
 def delete(self, where, table=None):
     result = False
     try:
         col = self.get_collection('delete', table)
         col += self.encode(where)
         result = NetworkHelper.get_json(col)
         result = result['row']
     except:
         LogHelper.log(sys.exc_info())
     return result
 def update_one(self, where, params, table=None):
     result = False
     try:
         col = self.get_collection('update_one', table)
         col += self.encode([where, params])
         result = NetworkHelper.get_json(col)
         result = result['row']
     except:
         LogHelper.log(sys.exc_info())
     return result
 def insert_one(self, params, table=None):
     result = False
     try:
         col = self.get_collection('insert_one', table)
         col += self.encode(params)
         result = NetworkHelper.get_json(col)
         result = result['row']
     except:
         LogHelper.log(sys.exc_info())
     return result
 def run_queue(self, params, callback):
     # https://www.linkedin.com/messaging/conversationsView?includeSent=true&clearUnseen=false&after=1486408991388
     LogHelper.log('EXECUTING ' + self.__class__.__name__, True)
     LogHelper.log('INPUT ' + self.__class__.__name__ + ' ' + str(params))
     self.db = DatasourceHelper.get_dataset({"table": self.DATABASE_TABLE})
     email = params['bots']['email']
     urls = params['conversation']
     for url in urls:
         contact = self.db.select_one({'email': email, 'url': url})
         self.waiting_list.append(url)
         self.maybe_init_listener(params, callback)
Esempio n. 12
0
 def waitGetCookies(self):
     cookies = {}
     try:
         cookies = self.driver.get_cookies()
     except:
         LogHelper.log(sys.exc_info())
     if cookies:
         return cookies
     else:
         time.sleep(0.2)
         return self.waitGetCookies()
    def run_queue(self, params, callback):
        LogHelper.log('EXECUTING ' + self.__class__.__name__, True)
        LogHelper.log('INPUT ' + self.__class__.__name__ + ' ' + str(params))
        self.db = DatasourceHelper.get_dataset({"table": self.DATABASE_TABLE})
        email = params['bots']['email']
        regex_expertise = []
        expertises = params['expertise'].split(',')
        for expertise in expertises:
            expertise = expertise.strip()
            regex_expertise.append(TextHelper.get_regexp(expertise))
        regex_location = []
        locations = params['location'].split(',')
        for location in locations:
            location = location.strip()
            regex_location.append(TextHelper.get_regexp(location))
        records = self.db.select({
            'email': email,
            'keywords': {
                '$in': regex_expertise
            },
            'where': {
                '$in': regex_location
            }
        })
        num_results = len(records)
        LogHelper.log('RESULTS_NUMBER', True)
        LogHelper.log(num_results, True)
        if num_results == 0:
            if email not in self.drivers:
                self.drivers[email] = LinkedinHelper.clone_driver_wait(
                    params['bots']['driver'])
            sel = self.drivers[email]
            args = {'driver': sel}
            profiles_finder = ProfilesFinder(args)
            args = params.copy()
            args['from_page'] = 1
            args['to_page'] = 1
            args['email'] = email

            def profiles_finder_callback(userData):
                self.db.insert_one(userData)
                output = {'contacts': [userData['url']]}
                LogHelper.log('OUTPUT ' + self.__class__.__name__ + ' ' +
                              str(output))
                self.pop(params, output, callback)

            profiles_finder.run(args, profiles_finder_callback)
        else:
            for record in records:
                output = {'contacts': [record['url']]}
                LogHelper.log('OUTPUT ' + self.__class__.__name__ + ' ' +
                              str(output))
                self.pop(params, output, callback)
				def messenger_callback(results):
					url = results['url']
					self.db.update_one({'email':email,'url':url},{'firstMessageSent':True})
					results['email'] = email
					results['type'] = 'OUTCOMING'
					results['message'] = params['message']
					results['connId'] = contact['connId']
					results['conversationId'] = conversation['conversationId']
					self.db.insert_one(results, table=self.MESSAGES_TABLE)
					output = {'conversation': [url]}
					LogHelper.log('OUTPUT ' + self.__class__.__name__ + ' ' + str(output))
					self.pop(params, output, callback)
def login_enter_credentials(driver, params):
    exit = False
    if driver.existElement(FIELD_LOGIN_USER):
        driver.selectAndWrite(FIELD_LOGIN_USER, params['email'])
        driver.selectAndWrite(FIELD_LOGIN_PASS, params['password'])
        driver.submitFormSelector(FIELD_LOGIN_PASS)
        time.sleep(0.4)
        # driver.waitPageLoad()
        title = driver.getTitle()
        LogHelper.log(title, True)
        if 'Error' not in title:
            exit = driver.waitGetCookies()
    return exit
Esempio n. 16
0
 def profiles_extractor_callback(userdata):
     self.db.update_one({
         'email': email,
         'url': url
     }, {
         'userId': userdata['connId'],
         'userdata': userdata,
         'extractedLogged': True
     })
     output = {'userdata': [url]}
     LogHelper.log('OUTPUT ' + self.__class__.__name__ + ' ' +
                   str(output))
     self.pop(params, output, callback)
	def check_messages(self, params, callback):
		email = params['bots']['email']
		while not self.stop_order:
			LogHelper.log('check_messages')
			self.sel.executeScript('tox.requestMessages()')
			time.sleep(2)
			result = self.sel.executeScript('return tox.getMessages()')
			if result:
				LogHelper.log(result)
				if 'conversationsAfter' in result and result['conversationsAfter']:
					for message in result['conversationsAfter']:
						callback(message)
			time.sleep(self.wait - 2)
Esempio n. 18
0
 def run_queue(self, params, callback):
     LogHelper.log('EXECUTING ' + self.__class__.__name__, True)
     LogHelper.log('INPUT ' + self.__class__.__name__ + ' ' + str(params),
                   True)
     ans = params["mod2out"] + params["mod3out"]
     out = {"mod4out": ans}
     print(out)
     self.pop(params, out, callback)
     ofile = open("output.csv", 'a')
     writer = csv.writer(ofile,
                         delimiter=' ',
                         quotechar='"',
                         quoting=csv.QUOTE_ALL)
     writer.writerow([ans])
 def run_queue(self, params, callback):
     LogHelper.log('EXECUTING ' + self.__class__.__name__, True)
     LogHelper.log('INPUT ' + self.__class__.__name__ + ' ' + str(params))
     LogHelper.log('PORT OPEN 0')
     output = {}
     LogHelper.log('OUTPUT ' + self.__class__.__name__ + ' ' + str(output))
     self.pop(params, output, callback)
Esempio n. 20
0
def start_server(params):
    global args
    LogHelper.log('CREATING SERVER')
    config_server(params)
    app = Flask(args['name'])
    CORS(app)
    app.add_url_rule('/',
                     '/',
                     honeypot,
                     methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH'])
    app.add_url_rule('/<path:path>',
                     '/<path:path>',
                     honeypot,
                     methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH'])
    args['app'] = app
    run_server()
 def run_queue(self, params, callback):
     LogHelper.log('EXECUTING ' + self.__class__.__name__, True)
     LogHelper.log('INPUT ' + self.__class__.__name__ + ' ' + str(params), True)
     with sqlite3.connect("content.db") as db:
         cursor=db.cursor()
     cursor.execute("""CREATE TABLE IF NOT EXISTS content(
         Domain VARCHAR(100),
         Content VARCHAR(500));""")
     value=params["mod2out"]
     resp=requests.get(value)
     soup= BeautifulSoup(resp.text,"lxml")
     cont=soup.find('body').text
     insert_vals=("INSERT INTO content(Domain,Content) VALUES(?,?)")
     cursor.execute(insert_vals,[(value),(cont)])
     db.commit()
     out={"mod3out":"content.db"}
     self.pop(params,out,callback)
 def check_connections(self, params, callback):
     email = params['bots']['email']
     protocol = 'http'
     while not self.stop_order:
         LogHelper.log('check_connections')
         self.sel.executeScript('tox.requestNotifications()')
         time.sleep(2)
         result = self.sel.executeScript('return tox.getNotifications()')
         if result:
             urls = TextHelper.text_between(
                 result, 'href="' + protocol,
                 '&amp;trk=hb_ntf_ACCEPTED_YOUR_CONNECTION_REQUEST')
             for url in urls:
                 url = protocol + url
                 callback([url])
             LogHelper.log(urls, True)
         time.sleep(5)
 def connection_listener_handler(urls):
     LogHelper.log(self.waiting_list, True)
     for url in urls:
         LogHelper.log('EVALUATING INCOMMING ACCEPT', True)
         LogHelper.log(url, True)
         if url in self.waiting_list:
             LogHelper.log('INCOMMING ACCEPT EVALUATED', True)
             self.waiting_list.remove(url)
             if not self.waiting_list:
                 self.listeners[email].stop()
             self.db.update({'url': url}, {
                 'accepted': True,
                 'status': 'ACCEPTED'
             })
             output = {'added': [url]}
             LogHelper.log('OUTPUT ' + self.__class__.__name__ +
                           ' ' + str(output))
             self.pop(params, output, callback)
 def run_queue(self, params, callback):
     LogHelper.log('EXECUTING ' + self.__class__.__name__, True)
     LogHelper.log('INPUT ' + self.__class__.__name__ + ' ' + str(params),
                   True)
     output = {}
     val = params["mod1out"]
     URL = "https://www.google.co.in/search?q=" + str(val)
     r = requests.get(URL)
     data = r.text
     soup = BeautifulSoup(data, "lxml")
     for item in soup.select('.r a'):
         myurl = item.get('href')
         u = myurl.find('http')
         if (u != -1):
             u = myurl.replace(myurl[:u], '')
             u = u.split('&')
             u = u[0]
             output["mod2out"] = u
             self.pop(params, output, callback)
 def run(self, params, callback=None, batch=False):
     results = self.generate_profiles(params)
     if batch:
         profiles = []
     for result in results['results']:
         profile = self.complete_profile(params, result)
         email_result = MailHelper.create_email(profile)
         LogHelper.log('EMAIL RESULT')
         LogHelper.log(email_result)
         profile['emailCreated'] = True
         if batch:
             profiles.append(profile)
         elif callback:
             callback(profile)
     if batch:
         if callback:
             callback(profiles)
         else:
             return profiles
 def generate_profiles(self, params):
     extra = ''
     nat = 'ES'
     num_results = 10
     if 'num_results' in params:
         num_results = int(params['num_results'])
     elif 'feedback' in params:
         if params['feedback'].isdigit():
             num_results = int(params['feedback'])
     extra += '&results=' + str(num_results)
     if params['gender']:
         if params['gender'] == 'male' or params['gender'] == 'female':
             extra += '&gender=' + params['gender']
     if params['location']:
         location = params['location'].split(',')[0].strip()
         nat = self.COUNTRIES.keys()[self.COUNTRIES.values().index(
             location)]
     url = self.RANDOM_USERS_API_URL + '?format=pretty&nat=' + nat + extra
     LogHelper.log(url, True)
     results = NetworkHelper.get_json(url)
     return results
Esempio n. 27
0
 def run_queue(self, params, callback):
     LogHelper.log('EXECUTING ' + self.__class__.__name__, True)
     LogHelper.log('INPUT ' + self.__class__.__name__ + ' ' + str(params))
     profiles = params['profiles']
     self.db = DatasourceHelper.get_dataset({"table": self.DATABASE_TABLE})
     for profile in profiles:
         email = profile['email']
         if email not in self.drivers:
             self.drivers[email] = LinkedinHelper.get_driver()
         sel = self.drivers[email]
         args = {'driver': sel}
         bots_creator = BotsCreator(args)
         record = self.db.select_one({'email': profile['email']})
         if not record['accountCreated']:
             bots_creator.createAccount(profile)
             self.db.update({'email': profile['email']}, {
                 'accountCreated': True,
                 'cookies': sel.getCookies()
             })
         else:
             cookies = LinkedinHelper.login(sel, profile)
             if cookies:
                 self.db.update({'email': email}, {'cookies': cookies})
         output = {'bots': {'email': profile['email'], 'driver': sel}}
         LogHelper.log('OUTPUT ' + self.__class__.__name__ + ' ' +
                       str(output))
         self.pop(params, output, callback)
 def webhook(self, params):
     LogHelper.log('WEBHOOK RECEIVED ...')
     info = params['json']
     LogHelper.log(info)
     if info:
         LogHelper.log('WEBHOOK JSON ...')
         url = ''
         for record in info:
             if record['verb'] == 'attempted' or record[
                     'verb'] == 'experienced':
                 if record['object']['objectType'] == 'Activity':
                     LogHelper.log('WEBHOOK FORMAT CORRECT...')
     StateMachineHelper.set_values('user',
                                   {'expertise': 'Software Engineer'})
     return '{"status":"webhook"}'
def load(params):
    global args
    LogHelper.log('STARTING', True)
    exit = '{"status":"OK"}'
    data = params['json']
    if data:
        exit = json.dumps(data)
        # LogHelper.log(exit)
        args['modules'] = {}
        values = []
        for module in data['modules']:
            args['modules'][module['name']] = get_obj(module['class'])
            LogHelper.log(module['name'] + ' = ' + module['class'] + '()')
            content = {}
            for field in module['fields']:
                args['modules'][module['name']].add_node(field)
                LogHelper.log(module['name'] + ".add_node(" +
                              json.dumps(field) + ")")
                if field['value']:
                    content[field['name']] = field['value']
            if content:
                values.append({'window': module['name'], 'content': content})
        for connection in data['connections']:
            args['modules'][connection['from']['window']].connect({
                'name':
                connection['from']['variable'],
                'target':
                args['modules'][connection['to']['window']]
            })
            LogHelper.log(connection['from']['window'] + ".connect({'name':'" +
                          connection['from']['variable'] + "', 'target':" +
                          connection['to']['window'] + "})")
        while values:
            record = values.pop()
            LogHelper.log(record['window'] + ".set_values(" +
                          json.dumps(record['content']) + ")")
            args['modules'][record['window']].set_values(record['content'])
    return exit
Esempio n. 30
0
    def __init__(self, config):
        '''
        Constructor: 
        This is going to setup the default configuration, if we need to parse the config file, 
        then need to call the configure method
        '''
        self.logger = LogHelper.getLogger()
        self.config = config
        self.logger.info("we are warming up... " + str(self.config.node_id))

        #=======================================================================
        # Setup the keyRing using the config...
        #    Also, Add yourself to the list...
        #=======================================================================
        self.key_manager.setupHashRing(self.config.peers, 3)
        self.key_manager.add_node(self.config.node_address)
	def run_queue(self, params, callback):
		LogHelper.log('EXECUTING ' + self.__class__.__name__, True)
		LogHelper.log('INPUT ' + self.__class__.__name__ + ' ' + str(params))
		exit = 'result messenger'
		email = params['bots']['email']
		urls = params['userdata']
		self.db = DatasourceHelper.get_dataset({"table": self.DATABASE_TABLE})
		for url in urls:
			contact = self.db.select_one({'email':email, 'url':url})
			conversation = {'conversationId':''}
			if contact['channel'] == 'Linkedin' and not contact['conversationId']:
				conversation = MBFHelper.new_conversation()
				self.db.update_one({'email':email,'url':url},{'conversationId':conversation['conversationId']})
			if not contact['firstMessageSent']:
				sel = LinkedinHelper.clone_driver(params['bots']['driver'])
				args = {'driver': sel}
				messenger = Messenger(args)
				def messenger_callback(results):
					url = results['url']
					self.db.update_one({'email':email,'url':url},{'firstMessageSent':True})
					results['email'] = email
					results['type'] = 'OUTCOMING'
					results['message'] = params['message']
					results['connId'] = contact['connId']
					results['conversationId'] = conversation['conversationId']
					self.db.insert_one(results, table=self.MESSAGES_TABLE)
					output = {'conversation': [url]}
					LogHelper.log('OUTPUT ' + self.__class__.__name__ + ' ' + str(output))
					self.pop(params, output, callback)
				params['url'] = contact['url']
				if 'connId' in contact:
					params['connId'] = contact['connId']
				else:
					params['connId'] = ''
				messenger.send_message(params, messenger_callback)
			else:
				output = {'conversation': [url]}
				LogHelper.log('OUTPUT ' + self.__class__.__name__ + ' ' + str(output))
				self.pop(params, output, callback)