U
    @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:   || _ |  | _d| _t| D ]}|| | j|< q"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|d|id}|d dkr\| jd	d
 d| _d S |d dkr|dkr| jdd
 d S td |d7 }| 	|||S |d s| jdd
 d S zt
|d }d|krFt| j d dkrFt|d d}tt| }tt dt| j d   }	||	k rF| jd W d S W n@ tk
r }
 z | jdt|
 d
 W Y d S d }
~
X Y 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   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   r7   ;   sD     


zsfp_fullcontact.queryc                 C   s   d}|  |d|iS )Nz-https://api.fullcontact.com/v3/company.enrichdomain)r7   )r   rI   r@   r   r   r   queryCompanyc   s    zsfp_fullcontact.queryCompanyc                 C   s:   d}t  }|s|sd S |r"||d< |r.||d< | ||S )Nz,https://api.fullcontact.com/v3/person.enrichfullNameemail)dictr7   )r   namerL   r@   qr   r   r   queryPersong   s    zsfp_fullcontact.queryPersonc                 C   sb  |j }|j}|j}| jrd S | jd dkrB| jdd d| _d S | jd| d |  || jkr|| jd| d	  d S d| j|< |d
kr| j	|d}|sd S |
dsd S tdd|d  | j|}| | d S |dkr^| |}|sd S |
dr|d }|
dr@|d D ]$}td
|d | j|}| | q|
drz|d D ]$}td|d | j|}| | qT|
dr|d D ]}|
dr|
drtd|d d |d  | j|}| | |
drt|d dkrtd|d | j|}| | q|
dr^|d D ]4}|
dr(tdd|d  | j|}| | q(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   )rL   rK   r   zPossible full name: r   detailsemailsvalueZphonesr   	locationscitycountryr   z, 	formatted
   r    Z	keyPeople)	eventTypemodulerA   r   r   r   r4   r=   r   rP   getr   __name__notifyListenersrJ   len)r   event	eventNamesrcModuleName	eventDatarA   rH   rr   r   r   handleEventu   s    


 


 

  zsfp_fullcontact.handleEvent)r   )NN)r\   
__module____qualname____doc__r   optdescsr   r   rM   r   r   r!   r7   rJ   rP   rd   r   r   r   r   r      s    
(
r   )r2   r5   r   sflibr   r   r   r   r   r   r   r   <module>   s   