3
@6^                 @   s0   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               @   sJ   e Zd ZdZddiZddiZdZe fddZdd	 Z	d
d Z
dd ZdS )sfp_crossrefz|Cross-Reference:Footprint:Crawling and Scanning::Identify whether other domains are associated ('Affiliates') of the target.	checkbaseTzMCheck the base URL of the potential affiliate if no direct affiliation found?Nc             C   s8   || _ | j | _x"t|j D ]}|| | j|< qW d S )N)sftempStoragefetchedlistkeysopts)selfsfcuserOptsopt r   7/var/www/spiderfoot.crq.systems/modules/sfp_crossref.pysetup$   s    
zsfp_crossref.setupc             C   s   ddddgS )NLINKED_URL_EXTERNALSIMILARDOMAINCO_HOSTED_SITEZDARKNET_MENTION_URLr   )r   r   r   r   watchedEvents,   s    zsfp_crossref.watchedEventsc             C   s   ddgS )NAFFILIATE_INTERNET_NAMEAFFILIATE_WEB_CONTENTr   )r   r   r   r   producedEvents2   s    zsfp_crossref.producedEventsc             C   s~  |j }|j}|j}| jjd| d |  |dkr>d|j  }| j j| jj|rl| jjd| d  d S || j	kr| jjd| d  d S d	| j	|< | jjd
|  | jj
|| jd | jd dd}|d d kr| jjd| d  d S d}xT| j j D ]D}tjd| d tj}tj||d }	t|	dk rd	}|}
P  qW |s|dkr| jd r| jj|}
|
| j	kr~d S d	| j	|
< | jj
|
| jd | jd dd}|d d k	rxN| j j D ]>}tjd| d tj}tj||d }	t|	dkrd	}qW |rz|jsd|_| jjd|
  td| jj|
| j|}|j|_| j| td|d | j|}|j|_| j| d S )NzReceived event, z, from r   r   zhttp://z	Ignoring z as not externalz as already testedTzTesting for affiliation: _fetchtimeout
_useragenti )timeout	useragent	sizeLimitcontentz as no data returnedFz([\.'\/"\ ]z[\.'\/"\ ])r   r   r   z	['\/"\ ])UnknownzFound affiliate: r   r   )r   r   )	eventTypemoduledatar   debuglower	getTargetmatchesurlFQDNr	   fetchUrlr   getNamesrecompile
IGNORECASEfindalllen
urlBaseUrlmoduleDataSourceinfor   __name__notifyListeners)r   event	eventNamesrcModuleName	eventDataresmatchednamepatr(   urlZevt1Zevt2r   r   r   handleEvent8   sn    







zsfp_crossref.handleEvent)r4   
__module____qualname____doc__r   optdescsr	   dictr   r   r   r?   r   r   r   r   r      s   r   )r,   sflibr   r   r   r   r   r   r   r   <module>   s   