Your IP : 216.73.216.86


Current Path : /lib/fm-agent/library/__pycache__/
Upload File :
Current File : //lib/fm-agent/library/__pycache__/forticlient_helper.cpython-36.pyc

3

q��i��@s@ddlZddlmZddlZeeed�dd�ZGdd�d�ZdS)�N)�path)�
ems_serial�environment�returncCs:tjd�}|j|j��|j|j��|j�dd�}|S)zO
    Calculate a new customer key based on the ems_serial and environment.
    �sha256r�)�hashlib�new�update�encode�	hexdigest)rrZhasher�customer_key�r�//usr/lib/fm-agent/library/forticlient_helper.py�calculate_customer_keys

rc@s4eZdZdZdZdd�Zdd�Zdd�Zd	d
�ZdS)�ForticlientHelperz7/Library/Application Support/Fortinet/FortiClient/data/z@/Library/Application Support/Fortinet/FortiClient/conf/vpn.plistcCsddd�|_tj�|_dS)NZforticlient_serialr)zfct_uid.confzEMS_sn.conf)�data_files_map�logging�	getLogger�log)�selfrrr�__init__s
zForticlientHelper.__init__cCs�y�ddlj}|j|�}|jdkr.|jd|�}|j}y|jd�}|d|�}WnYnX|j�jd�}t|�dkrzdS|d}|d}|d}	t|�d
kr�|d}
n|d}
|dkr�|d
kr�|
dkr�|	SdSdSdS)Nr�zhttp://�:�.������ZcomZ	fortisase�edge���������������)	�urllib.parse�parse�urlparse�scheme�netloc�index�lower�split�len)r�urlr)Zparsed�host�idxZ
host_partsZ	top_level�domainrr!rrr�
parse_addresss2




zForticlientHelper.parse_addresscCsnddl}t|jd��H}|j|�}x6|dj�D]&}|jdd�}|r.|j|�}|r.|Sq.WWdQRXtd��dS)Nr�rbZProfilesZServerzNo environment profile found)�plistlib�open�vpn_data�load�values�getr4�	Exception)rr6�f�dataZprofileInfo�server_name�envrrr�get_vpn_environmentFs

z%ForticlientHelper.get_vpn_environmentcCs�tj|j�std��i}d}x^|jj�D]P\}}|d7}ttj|j|�d��&}|j�j	�}t
|�dkrn|||<WdQRXq(Wt
|j��|kr�td��y|j�|d<Wntd��YnX|S)NzMissing forticlient datarr�rzMissing forticlient keys�forticlient_environmentzMissing VPN data)
r�isdir�	data_pathr<r�itemsr7�join�readline�stripr/�keysrA)r�rvZ	key_count�fileZhs_keyZdfZdvrrr�get_handshake_dataTs"z$ForticlientHelper.get_handshake_dataN)	�__name__�
__module__�__qualname__rEr8rr4rArMrrrrrs
'r)r�osrr�strrrrrrr�<module>s