3
@6^|                 @   sD   d dl Z d dlZd dlmZ d dlmZmZmZ G dd deZdS )    N)datetime)
SpiderFootSpiderFootPluginSpiderFootEventc               @   sn   e Zd ZdZdddZdddZdZdZe fd	d
Z	dd Z
dd ZdddZdd ZdddZdd ZdS )sfp_fullcontactzzFullContact:Footprint,Investigate,Passive:Search Engines:apikey:Gather domain and e-mail information from fullcontact.com. 365)api_keymax_age_dayszFullcontact.com API key.z[Maximum number of age in days for a record before it's considered invalid and not reported.NFc             C   s>   || _ | j | _d| _x"t|j D ]}|| | j|< q$W d S )NF)sftempStorageresults
errorStatelistkeysopts)selfsfcuserOptsopt r   :/var/www/spiderfoot.crq.systems/modules/sfp_fullcontact.pysetup'   s
    
zsfp_fullcontact.setupc             C   s   ddgS )NDOMAIN_NAME	EMAILADDRr   )r   r   r   r   watchedEvents3   s    zsfp_fullcontact.watchedEventsc             C   s   dddddgS )Nr   RAW_RIR_DATAPHONE_NUMBERGEOINFOPHYSICAL_ADDRESSr   )r   r   r   r   producedEvents7   s    zsfp_fullcontact.producedEventsr   c             C   s  d| j d  }d }| jj|| j d dtj|d|id}|d dkr\| jjd
d d| _d S |d dkr|dkr| jjdd d S tjd |d7 }| j	|||S |d s| jjdd d S ytj
|d }d|kot| j d dkrBtj|d d}ttj|j }ttj dt| j d   }	||	k rB| jjd d S W n8 tk
r| }
 z| jjdt|
 d d S d }
~
X nX |S )NzBearer r	   _fetchtimeoutr   Authorization)timeout	useragentpostDataheaderscode401400z#API key rejected by fullcontact.comFT403   z.Throttled or other blocking by fullcontact.com      contentz(No content returned from fullcontact.comupdatedr
   r   z%Y-%m-%diQ z(Fullcontact.co record found but too old.z5Error processing JSON response from fullcontact.com: )r(   r)   )r   r   fetchUrljsondumpserrorr   timesleepqueryloadsintr   strptimemktime	timetupledebug	Exceptionstr)r   urldataZ	failcountheaderretreslast_dtlast_tsage_limit_tser   r   r   r6   ;   s@    


zsfp_fullcontact.queryc             C   s   d}| j |d|iS )Nz-https://api.fullcontact.com/v3/company.enrichdomain)r6   )r   rH   r?   r   r   r   queryCompanyc   s    zsfp_fullcontact.queryCompanyc             C   s>   d}t  }| r| rd S |r&||d< |r2||d< | j||S )Nz,https://api.fullcontact.com/v3/person.enrichfullNameemail)dictr6   )r   namerK   r?   qr   r   r   queryPersong   s    zsfp_fullcontact.queryPersonc             C   sr  |j }|j}|j}| jrd S | jd dkrB| jjdd d| _d S | jjd| d |  || jkr|| jjd| d	  d S d| j|< |d
kr| j	|d}|sd S |j
dsd S tdd|d  | j|}| j| d S |dkrn| j|}|sd S |j
dr|d }|j
drDx0|d D ]$}td
|d | j|}| j| qW |j
drx0|d D ]$}td|d | j|}| j| qZW |j
dr x|d D ]}|j
dr|j
drtd|d d |d  | j|}| j| |j
drt|d dkrtd|d | j|}| j| qW |j
drnx@|d D ]4}|j
dr6tdd|d  | j|}| j| q6W d S )Nr	   r   z7You enabled sfp_fullcontact but did not set an API key!FTzReceived event, z, from z	Skipping z as already mapped.r   )rK   rJ   r   zPossible full name: r   detailsemailsvalueZphonesr   	locationscitycountryr   z, 	formatted
   r   Z	keyPeople)	eventTypemoduler@   r   r   r   r3   r<   r   rO   getr   __name__notifyListenersrI   len)r   event	eventNamesrcModuleName	eventDatar@   rG   rr   r   r   handleEventu   sn    









zsfp_fullcontact.handleEvent)r   )NN)r[   
__module____qualname____doc__r   optdescsr   r   rL   r   r   r    r6   rI   rO   rc   r   r   r   r   r      s   
(
r   )r1   r4   r   sflibr   r   r   r   r   r   r   r   <module>   s   