U
    @6^                     @   s8   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                   @   sF   e Zd ZdZi Zi ZdZdZe fddZ	dd Z
dd	 Zd
d ZdS )sfp_callernamezpCallerName:Footprint,Investigate,Passive:Real World::Lookup US phone number location and reputation information.NFc                 C   s@   || _ d| _|  | _d| _t| D ]}|| | j|< q(d S )NZ
CallerNameF)sf__dataSource__tempStorageresults
errorStatelistkeysopts)selfsfcuserOptsopt r   9/var/www/spiderfoot.crq.systems/modules/sfp_callername.pysetup    s    
zsfp_callername.setupc                 C   s   dgS )NPHONE_NUMBERr   r   r   r   r   watchedEvents*   s    zsfp_callername.watchedEventsc                 C   s   ddgS )NGEOINFOMALICIOUS_PHONE_NUMBERr   r   r   r   r   producedEvents.   s    zsfp_callername.producedEventsc                 C   s  |j }|j}|j}| jrd S || jkr*d S d| j|< | jd| d |  |dsj| jd|  d S |d	d	d	d	d	}|
 s| jd
|  d S d| }| jj|| jd | jd d}td |d d kr| jd d S |d dkr| jd|  d S td|d tjtjB }|r|d }	t|	dk sZt|	dkrh| jd ntd|	| j|}
| |
 td|d }td|d }|r|rt|d }t|d }||krd| d d | d  }td!|| j|}
| |
 d S )"NTzReceived event, z, from z+1zUnsupported phone number: ()- zInvalid phone number: zhttps://callername.com/_fetchtimeout
_useragent)timeout	useragent   contentzNo response from CallerName.comcode200zNo phone information found for z4<div class="callerid"><h4>.*?</h4><p>(.+?)</p></div>r      d   z!Skipping likely invalid location.r   z>SAFE.*?>(\d+) votes?<z>UNSAFE.*?>(\d+) votes?<zCallerName [z]
z<SFURL>z</SFURL>r   )	eventTypemoduledatar
   r	   r   debug
startswithlstripstripisdigitfetchUrlr   timesleeprefindall	MULTILINEDOTALLlenr   __name__notifyListenersint)r   event	eventNamesrcModuleName	eventDatanumberurlresZlocation_matchlocationevtZrep_good_matchZrep_bad_matchZ
good_votesZ	bad_votestextr   r   r   handleEvent2   sR    


"


zsfp_callername.handleEvent)r9   
__module____qualname____doc__r   optdescsr	   r
   dictr   r   r   rF   r   r   r   r   r      s   
r   )r4   r2   sflibr   r   r   r   r   r   r   r   <module>   s   