Sindbad~EG File Manager

Current Path : /lib/python3.6/site-packages/sos/cleaner/mappings/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/sos/cleaner/mappings/__pycache__/hostname_map.cpython-36.opt-1.pyc

3

�f�(�@s(ddlZddlmZGdd�de�ZdS)�N)�SoSMapc
s�eZdZdZdddgZddgZd%ZdZdZdZ	dZ
iZiZdd�Z
dd�Zdd�Zdd�Z�fdd�Zdd�Zdd �Zd!d"�Zd#d$�Z�ZS)&�SoSHostnameMapaLMapping store for hostnames and domain names

    Hostnames are obfuscated using an incrementing counter based on the total
    number of hosts matched regardless of domain name.

    Domain names are obfuscated based on the host's hostname, plus any user
    defined domains passed in by the `--domains` options.

    Domains are obfuscated as whole units, meaning the domains 'example.com'
    and 'host.foo.example.com' will be separately obfuscated with no relation
    for example as 'obfuscatedomdain1.com' and 'obfuscatedomain2.com'.

    Top-level domains are left untouched.
    Z	localhostz.*localdomain.*z^com..*ZwwwZapi�.yaml�.yml�.crt�.key�.pem�.log�.repo�.rules�.conf�.cfgTrcCs�x�|jj�D]�\}}t|jd��dkrB|j||j|jd�d<q|jd�rb|jd�d|j|<qdj|jd�dd��}|s�qxZ|jj�D]L}dj|jd�dd��}||kr�dj|j|jd�dd��}||j|<q�WqW|j	�dS)	z�Because we use 'intermediary' dicts for host names and domain names
        in this parser, we need to re-inject entries from the map_file into
        these dicts and not just the underlying 'dataset' dict
        �.�rZobfuscateddomainN���rr)
�dataset�items�len�split�hosts�
startswith�_domains�join�keys�set_initial_counts)�self�domainZob_pairZ_domain_to_injectZexisting_domain�	_existingZ
_ob_domain�r�"/usr/lib/python3.6/hostname_map.py�load_domains_from_map5s 
z$SoSHostnameMap.load_domains_from_mapcCs"d|kr|jdd�}tj|tj�S)z�Override the base get_regex_result() to provide a regex that, if
        this is an FQDN or a straight domain, will include an underscore
        formatted regex as well.
        rz(\.|_))�replace�re�compile�I)r�itemrrr�get_regex_resultUszSoSHostnameMap.get_regex_resultcCs�y2t|jj�dd�djd�d}t|�d|_Wntk
rFYnXy<t|jj�dd�djd�}t|djd�d�d|_Wntk
r�YnXdS)	z�Set the initial counter for host and domain obfuscation numbers
        based on what is already present in the mapping.
        T)�reverser�hostrrrN)	�sortedr�valuesr�int�
host_count�
IndexErrorr�domain_count)r�h�drrrr^s  z!SoSHostnameMap.set_initial_countscsj||jkrdS|jd�}dj|jd�dd���t|�dkrJ|d|jkSt�fdd�|jD��rfdSdS)	zkCheck if a potential domain is in one of the domains we've loaded
        and should be obfuscated
        Trrrcsg|]}�j|��qSr)�endswith)�.0Z_d)�no_tldrr�
<listcomp>}sz@SoSHostnameMap.domain_name_in_loaded_domains.<locals>.<listcomp>Fr)rrrrr�any)rrr(r)r3r�domain_name_in_loaded_domainsrs

z,SoSHostnameMap.domain_name_in_loaded_domainscs�d}d}d}x&|jd�r2||d7}|dd�}qWx&|jd�rZ||d
7}|dd�}q6W||jkrp|j|S|j|j��s�dj|||g�S|j|j�r�d|jd�d}|j|d�}||7}||jj	�k�rؐxt
|jj	�ddd�d	�D]�}d
}|j|�}|jd�}	|	d�r*|	d|jj	�k�r*d}t|�dks�|d�rFq�q�|�r~|djd��sj|j|��r~t
t|�j|�}Pq�|j|d�r�y0|j|d�d}
|dt
t|�j|
�}PWq�tk
�r�Yq�Xq�W|�s�t
t|�j|�}|||S)N�r�_rrTcSst|�S)N)r)�xrrr�<lambda>�sz$SoSHostnameMap.get.<locals>.<lambda>)r'�keyF)rr8)rr8rrr)rr1rr6�lowerr�
strip_extsrr!rr)rr�superr�get�	Exception)rr%�prefix�suffix�finalZextrZ_host_substrZ_testZ_hZitm)�	__class__rrr?�sR




zSoSHostnameMap.getc	Cs�|jd�}t|�dkr(|j|dj��St|�dkr\|j|�}tdd�|D��rX|j�}|St|�dkr�|d}|dd�}t|�dkr�|j|j��}nd}|j|�}||j|<dj||g�}tdd�|D��r�|j�}|SdS)	Nrrr�cSsg|]}|j��qSr)�isupper)r2r/rrrr4�sz0SoSHostnameMap.sanitize_item.<locals>.<listcomp>�unknowncSsg|]}|j��qSr)rF)r2r/rrrr4�s)	rr�sanitize_short_namer<�sanitize_domain�all�upperrr)	rr%r(�dname�hostnamerZob_hostname�	ob_domainZ_fqdnrrr�
sanitize_item�s*



zSoSHostnameMap.sanitize_itemcCs^|s||jkr|S||jkrTd|j}||j|<|jd7_||j|<|j|�|j|S)z�Obfuscate the short name of the host with an incremented counter
        based on the total number of obfuscated host names
        zhost%sr)�	skip_keysrr,rZadd_regex_item)rrMZob_hostrrrrH�s




z"SoSHostnameMap.sanitize_short_namecCszx*|jD] }tj|dj|��rdj|�SqW|dj�}dj|dd��j�}|j|�}dj||g�}||jdj|�<|S)zeObfuscate the domainname, broken out into subdomains. Top-level
        domains are ignored.
        rrrrr)�ignore_matchesr"�matchrr<�_new_obfuscated_domainr)rrZ_skipZ
top_domainrLrNrrrrI�s
zSoSHostnameMap.sanitize_domaincCs2||jkr(d|j|j|<|jd7_|j|S)zDGenerate an obfuscated domain for each subdomain name given
        zobfuscateddomain%sr)rr.)rrLrrrrS�s
z%SoSHostnameMap._new_obfuscated_domain)
rrrrrr	r
rrr
)�__name__�
__module__�__qualname__�__doc__rQrPr=Zignore_short_itemsZmatch_full_words_onlyr,r.rrr r&rr6r?rOrHrIrS�
__classcell__rr)rDrrs. 	< r)r"Zsos.cleaner.mappingsrrrrrr�<module>s

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists