3
@6^                  @   sl   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 dddggdddggd	d
dggdZ	G dd deZ
dS )    N)
SpiderFootSpiderFootPluginSpiderFootEventz"{name}"+site:facebook.comz;[ '"](https?://[a-z\.]*facebook.[a-z\.]+/[^/"'<> ]+/?)['" ]z:(https?%3a%2f%2f[a-z\.]*facebook.[a-z\.]+%2f[^\/"'<> ]+/?)z"{name}"+site:plus.google.comz8[ '"](https?://plus.google.[a-z\.]+/\d+[^"'<>\/ ]+)['" ]z6(https?%3a%2f%2fplus.google.[a-z\.]+%2f\d+[^\/"'<> ]+)z"{name}"+site:linkedin.comz:["' ](https?://[a-z\.]*linkedin.[a-z\.]+/[^\?"'<> ]+)['" ]z8(https?%3a%2f%2f[a-z\.]*linkedin.[a-z\.]+%2f[^\?"'<> ]+))FacebookzGoogle+ZLinkedInc               @   sf   e Zd ZdZdddddddZdd	d
ddddZdZdZdZe	 fddZ
dd Zdd Zdd ZdS )sfp_socialprofileszSocial Media Profiles:Footprint,Passive:Social Media:slow,apikey:Tries to discover the social media profiles for human names identified.   bingT z!013611106330597893267:tfgl3wxdtbp)countmethodtightenbing_api_keygoogle_api_keygoogle_cse_idzONumber of bing search engine results of identified profiles to iterate through.z)Search engine to use: 'google' or 'bing'.zyTighten results by expecting to find the keyword of the target domain mentioned in the social media profile page results?z-Bing API Key for social media profile search.z/Google API Key for social media profile search.zGoogle Custom Search Engine ID.NFc             C   sD   || _ | j | _d | _d| _x"t|j D ]}|| | j|< q*W d S )NF)sftempStorageresultskeywords
errorStatelistkeysopts)selfsfcuserOptsopt r   =/var/www/spiderfoot.crq.systems/modules/sfp_socialprofiles.pysetupH   s    
zsfp_socialprofiles.setupc             C   s   dgS )N
HUMAN_NAMEr   )r   r   r   r   watchedEventsR   s    z sfp_socialprofiles.watchedEventsc             C   s   ddgS )NSOCIAL_MEDIARAW_RIR_DATAr   )r   r   r   r   producedEventsX   s    z!sfp_socialprofiles.producedEventsc             C   s  |j }|j}|j}|| _| jr"d S | jjd| d |  | jd dkrn| jd dkrn| jjdd d| _d S || j	kr| jjd	| d
  d S d| j	|< | j
d kr| jj| j j | jd | _
t| j
dkrd | _
xtD ]}tt| d j|d}|jdd}d }| jd j dkr2| jjdd d S | jd j dkr~| jj|| jd | jd | jd | jd dd}d| _| jd j dkr| jj|| jd | jd | jd | jd dd}d| _|d kr| jjd| jd  d  q| j rd S td t|| j|}	| j|	 t }
xt| d! D ]~}dj|d" t|g }tj||tj tj!B }|spq2x<|D ]2}| jjd#|  ||
krqxn
|
j"| | j rd S | jd$ r`| j
r`t#j$j%|}| jjd%t| j
  | jj&|| jd | jd d&}|d' d krqxnBd}x2| j
D ](}tj'd(| d( |d' tj r*d}q*W |s`qx| jjd)| d* |  t#j$j%|}td+|d, | d- | j|}	| j|	 qxW q2W qW d S ).NzReceived event, z, from r   r	   r   zHYou enabled sfp_socialprofiles but did not set a Google or Bing API key!FTz	Skipping z as already mapped._internettldsr   )name z%20r   Zyahooz<Yahoo is no longer supported. Please try 'bing' or 'google'.Zgoogle_fetchtimeout
_useragentr   )timeout	useragentapi_keycse_id)searchStringr   ZGoogler   r
   )r)   r*   r
   r+   ZBingzNo data returned from .r"      urlszMatch found: r   zTightening results to look for )r)   r*   contentz[^a-zA-Z\-\_]zSocial Media Profile found at z: r!   z	: <SFURL>z</SFURL>)(	eventTypemoduledatacurrentEventSrcr   r   debugr   errorr   r   domainKeywords	getTargetgetNameslensitesstrformatreplacelowergoogleIterate__dataSource__bingIterateinfocheckForStopr   __name__notifyListenersr   joinrefindall
IGNORECASE	MULTILINEappendurllibparseunquotefetchUrlsearch)r   event	eventNamesrcModuleName	eventDatasitesZ	searchStrresevtZ	instancesZ	searchDomsearch_stringmatchesmatchZpresfoundkwr   r   r   handleEvent\   s    











zsfp_socialprofiles.handleEvent)rF   
__module____qualname____doc__r   optdescsr   r   r   dictr   r    r#   r`   r   r   r   r   r   -   s(   
r   )rI   urllib.requestrN   urllib.errorurllib.parsesflibr   r   r   r<   r   r   r   r   r   <module>   s   