U
    @6^M                     @   sH   d dl Z d dlZd dlZd dlZd dlmZmZmZ G dd deZ	dS )    N)
SpiderFootSpiderFootPluginSpiderFootEventc                   @   sV   e Zd ZdZdddZdddZdZe fdd	Zd
d Z	dd Z
dd Zdd ZdS )sfp_citadelz~Citadel Engine:Footprint,Investigate,Passive:Leaks, Dumps and Breaches:apikey:Searches Leak-Lookup.com's database of breaches. <   )api_keytimeoutzCLeak-Lookup API key. Without this you're limited to the public API.z-Custom timeout due to heavy traffic at times.Nc                 C   s:   || _ |  | _d| _t| D ]}|| | j|< q"d S )NzLeak-Lookup.com)sftempStorageresults__dataSource__listkeysopts)selfsfcuserOptsopt r   6/var/www/spiderfoot.crq.systems/modules/sfp_citadel.pysetup    s
    
zsfp_citadel.setupc                 C   s   dgS )N	EMAILADDRr   r   r   r   r   watchedEvents)   s    zsfp_citadel.watchedEventsc                 C   s   dgS )NEMAILADDR_COMPROMISEDr   r   r   r   r   producedEvents/   s    zsfp_citadel.producedEventsc              
   C   s   | j d }|sd}|djdddd|d}| jjd	tj|| j d
 | j d d}|d d krr| jd d S zt	
|d }W n< tk
r } z| jdt|  W Y d S d }~X Y nX |S )Nr   Z 3edfb5603418f101926c64ca5dd0e409raw_unicode_escapeasciireplace)errorsZemail_address)querytypekeyz"https://leak-lookup.com/api/searchr	   
_useragent)postDatar	   	useragentcontentz No response from Leak-Lookup.comz Error processing JSON response: )r   encodedecoder
   fetchUrlurllibparse	urlencodedebugjsonloadsBaseExceptionstr)r   emailZapikeyparamsresdataer   r   r   
queryEmail4   s*    

zsfp_citadel.queryEmailc           
      C   s
  |j }|j}|j}| jd| d |  | jr4d S || jkrV| jd| d  d S d| j|< | |}|d krvd S |d}|d}|dkr| j	d	
||d
 d|krd| _d S d S |sd S |D ]:}| jd
|| tdd
||| j|}	| |	 qd S )NzReceived event, z, from z	Skipping z as already searched.Terrormessagetruez#Error encountered processing {}: {}FzMISSING APIz"Found Leak-Lookup entry for {}: {}r   z{} [{}])	eventTypemoduler6   r
   r.   
errorStater   r8   getr9   formatinfor   __name__notifyListeners)
r   event	eventNamesrcModuleName	eventDatar6   r9   r:   siteevtr   r   r   handleEventS   s6    




zsfp_citadel.handleEvent)rB   
__module____qualname____doc__r   optdescsr   dictr   r   r   r8   rJ   r   r   r   r   r      s   	r   )
r/   urllib.requestr+   urllib.parseurllib.errorsflibr   r   r   r   r   r   r   r   <module>   s   