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               @   sN   e Zd ZdZddiZddiZe fddZdd Zd	d
 Z	dd Z
dd ZdS )
sfp_githubz^Github:Footprint,Passive:Social Media::Identify associated public code repositories on Github.	namesonlyTzYMatch repositories by name only, not by their descriptions. Helps reduce false positives.c             C   s8   || _ | j | _x"t|j D ]}|| | j|< qW d S )N)sftempStorageresultslistkeysopts)selfsfcuserOptsopt r   5/var/www/spiderfoot.crq.systems/modules/sfp_github.pysetup   s    
zsfp_github.setupc             C   s
   dddgS )NDOMAIN_NAMEUSERNAMESOCIAL_MEDIAr   )r   r   r   r   watchedEvents&   s    zsfp_github.watchedEventsc             C   s
   dddgS )NRAW_RIR_DATAGEOINFOPUBLIC_CODE_REPOr   )r   r   r   r   producedEvents,   s    zsfp_github.producedEventsc             C   s   d }|j dd kr"| jjd d S |j dd kr@| jjd d S |j dd kr^| jjd d S d|d  d d	 |d  d d
 |d  }|S )Nnamez+Incomplete Github information found (name).html_urlz*Incomplete Github information found (url).descriptionz2Incomplete Github information found (description).zName: 
zURL: zDescription: )getr   debug)r   item	repo_infor   r   r   buildRepoInfo0   s    ,zsfp_github.buildRepoInfoc          [   C   s  |j }|j}|j}|| jkr4| jjd| d  d S d| j|< |dkrly0|jdd }|jdd jdd	jd
d	}W nB tk
r } z&| jj	d| d t
| d d d S d }~X nX |dks| jjd| d  d S y|jd}|t|d  }	W n2 tk
r, } z| jjd|  d S d }~X nX | jjd|	 | jd | jd d}
|
d d krbd S ytj|
d }W n. tk
r } z| jjd d S d }~X nX |jds| jj|	d  d S |jds| jj|	d  d S tdd|d  | j|}| j| |jd}|d krd S t|d k s:t|d!krN| jjd"|  d S td#|| j|}| j| d S |d$kr| jj|| jd% }	|d&kr|}	| jjd'|	  d}d(|	 }| jj|| jd | jd d}
|
d d kr| jj	d)| d d}ytj|
d }W n( tk
r0 } z
d }W Y d d }~X nX |d krR| jj	d*|	 d d}|s|jd+d,d,ks|t|d- dkr| jjd.|	  d}|sx^|d- D ]R}| j|}|d kr| jd/ r|	|d kr֐qtd0|| j|}| j| qW d}d1|	 }| jj|| jd | jd d}
|
d d krD| jj	d)| d d}|sy2tj|
d }|d krz| jj	d*|	 d d}W n: tk
r } z| jj	d2|	 d d}W Y d d }~X nX |s|jd+d,d,kst|d- dkr| jjd.|	  d}|sx|d- D ]|}|jd3d kr.| jjd4 q|d3 }| jj|| jd | jd d}
|
d d krx| jj	d)| d qytj|
d }W n6 tk
r } z| jj	d5d wW Y d d }~X nX |d kr| jj	d*|	 d qx|D ]}t|tkr
| jjd6 q| j|}|d kr| jd/ r<|d |	kr<q|d&krdd|	 d |jd7d	krdqtd0|| j|}| j| qW qW d S )8NzAlready did a search for z, skipping.Tr   z: r      z<SFURL> z</SFURL>zUnable to parse SOCIAL_MEDIA: z ()FZGithubz!Skipping social network profile, z, as not a Github profile/zCouldn't get a username out of zhttps://api.github.com/users/_fetchtimeout
_useragent)timeout	useragentcontentzError processing JSON response.loginz is not a valid Github profiler   r   zPossible full name: location   d   z"Skipping likely invalid location: r   r   _internettldsr   zLooking at z-https://api.github.com/search/repositories?q=zUnable to fetch z2Unable to process empty response from Github for: Ztotal_count0itemszNo Github information for r   r   z&https://api.github.com/search/users?q=z4Unable to process invalid response from Github for: Z	repos_urlz0Incomplete Github information found (repos_url).z"Invalid JSON returned from Github.z8Encountered an unexpected or empty response from Github.r   )	eventTypemoduledatar	   r   r!   splitreplaceBaseExceptionerrorstrlenfetchUrlr   jsonloadsr    r   __name__notifyListenersdomainKeywordr$   typedict)r   event	eventNamesrcModuleName	eventDatanetworkurlebitsr   resZ	json_datar/   failedretr"   r#   evtZrepretr   r   r   handleEventC   s   


"
"







$





$




$
zsfp_github.handleEventN)rA   
__module____qualname____doc__r   optdescsrE   r   r   r   r$   rR   r   r   r   r   r      s   r   )r?   sflibr   r   r   r   r   r   r   r   <module>   s   