AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /proc/thread-self/root/usr/share/netplan/netplan/cli/commands/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /proc/thread-self/root/usr/share/netplan/netplan/cli/commands/__pycache__/migrate.cpython-310.pyc
o

|hEc�O�@s�dZddlZddlZddlZddlZddlmZzddlZdZWney+dZYnwddl	m
Z
ddlZddlm
mZGdd�dej�ZdS)	znetplan migrate command line�N)�globFT)�OrderedDictcsVeZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	ddd�Z
�ZS)�NetplanMigratecst�jddddd�dS)N�migratez/Migration of /etc/network/interfaces to netplanT)�
command_id�description�leaf�testing)�super�__init__��self��	__class__��2/usr/share/netplan/netplan/cli/commands/migrate.pyr%s

�zNetplanMigrate.__init__cCs�d|vr3d|vri|d<d|dvrg|dd<|d�d�D]}|s$q|dd|g7<q|d=d|vrhd|vr?i|d<d|dvrKg|dd<|d�d�D]}|sWqR|dd|g7<qR|d=dSdS)z�Parse dns options (dns-nameservers and dns-search) from if_options
        (an interface options dict) into the interface configuration if_config
        Mutates the arguments in place.
        zdns-nameservers�nameservers�	addresses� z
dns-search�searchN)�split)r
�
if_options�	if_config�ns�domainrrr�parse_dns_options+s*
�z NetplanMigrate.parse_dns_optionsc	Cs�d|vrFzt|d�}Wnty#t�d||d�t�d�Ynwd|vr=|d|ks=t�d|||d�t�d�||d<|d=dSdS)z�Parse out the MTU. Operates the same way as parse_dns_options
        iface is the name of the interface, used only to print error messages
        �mtuz%s: cannot parse "%s" as an MTU�z0%s: tried to set MTU=%d, but already have MTU=%dN)�int�
ValueError�logging�error�sys�exit)r
�ifacerrrrrr�	parse_mtuHs�

�zNetplanMigrate.parse_mtucCs\d|vr,d|vr!|d|dks!t�d||d|d�t�d�|d|d<|d=dSdS)z�Parse out the manually configured MAC.
        Operates the same way as parse_dns_options
        iface is the name of the interface, used only to print error messages
        �	hwaddress�
macaddressz0%s: tried to set MAC %s, but already have MAC %srN)r r!r"r#)r
r$rrrrr�parse_hwaddress[s�

�zNetplanMigrate.parse_hwaddresscCsV|jjddd�|jjdddd�|j|_|��tr%t�d�t�	d	�|�
�dS)
Nz
--root-dirzOSearch for and generate configuration files in this root directory instead of /)�helpz	--dry-run�
store_truezQPrint converted netplan configuration to stdout instead of writing/changing files)�actionr)z�The `yaml` Python package couldn't be imported, and is needed for the migrate command.
To install it on Debian or Ubuntu-based system, run `apt install python3-yaml`�)�parser�add_argument�command_migrate�func�
parse_args�NO_YAMLr r!r"r#�run_commandrrrr�runjs�
�

zNetplanMigrate.runcCs
i}z|�|jp	d�\}}Wnty,}zt�t|��t�d�WYd}~nd}~ww|��D�]9\}}|��D�]/\}}t�	d|||�||vrVt�d|�t�d�|ddkrct�	d|�q:|ddkr�|�
d	i��
d
i��
|i�}	|�|d|	�|�||d|	�|dr�t�d|d
�
|d����t�d�|dkr�d|	d<q:|dks�J�d|	d<q:|ddk�r\|�
d	i��
d
i��
|i�}	d|	vr�g|	d<|�|d|	�|�||d|	�|�||d|	�|dk�r�tgd��}
tgd��}t|d���}||
}
|
�r5|
�|�D]}t�d|||�t�d��q|
|D]}t�d|||�t�d��q$d|dv�rGt�d|�t�d�d|ddv�rb|dd�d�d}|dd}n&d|dv�rtt�d|�t�d�|dd}|ddd|dd}zt�|�}Wn!tj�y�}zt�d|||�t�d�WYd}~nd}~wwz	tj|d d!�}Wn!tj�y�}zt�d"|||�t�d�WYd}~nd}~ww|	dt|�dt|j�g7<d#|dv�r�|dd#|	d$<q:|dk�sJ�tgd%��}
tgd&��}t|d���}||
}
|
�rK|
�|�D]}t�d|||�t�d��q%|
|D]}t�d|||�t�d��q:d|dv�r]t�d|�t�d�d|ddv�rx|dd�d�d}|dd}n&d|dv�r�t�d|�t�d�|dd}|ddd|dd}zt�|�}Wn!tj�y�}zt�d'|||�t�d�WYd}~nd}~wwz	tj|d d!�}Wn!tj�y�}zt�d(|||�t�d�WYd}~nd}~ww|	dt|�dt|j�g7<d#|dv�r|dd#|	d)<d*|dv�r[|dd*d+k�r(d |	d*<q:|dd*d,k�r6d|	d*<q:|dd*d-k�rKt�d.|�t�d�q:t�d/||dd*�t�d�q:t�d0||d�t�d�q:q1tj�
|j�ptdd1�}|�r�d|d	d2<t�|�}|j�r�t |�n`tj�
|j�p�dd3�}zt�!tj�"|��Wn
t#�y�Ynwzt$|d4��
}|�%|�Wd�n	1�s�wYWnt#�y�t�d5|�t�d6�Ynwt�&d7|�nt�&d8�|j�st�&d9||�t�'||d:�dSdS);N�rzConverting %s family %s %sz.%s: non-automatic interfaces are not supported�method�loopbackzIgnoring loopback interface %s�dhcp�network�	ethernets�optionsz2%s: option(s) %s are not supported for dhcp methodz, �inetT�dhcp4�inet6�dhcp6�staticr)�address�netmask�gateway)�	broadcast�metric�pointopoint�scopez%s: unsupported %s option "%s"z%s: unknown %s option "%s"rAz(%s: no address supplied in static method�/rrBzE%s: address does not specify prefix length, and netmask not specifiedz-%s: error parsing "%s" as an IPv4 address: %sF)�strictz-%s: error parsing "%s" as an IPv4 network: %srC�gateway4)rArBrC�	accept_ra)rE�media�autoconf�privextrGzpreferred-lifetimezdad-attemptszdad-intervalz-%s: error parsing "%s" as an IPv6 address: %sz-%s: error parsing "%s" as an IPv6 network: %s�gateway6rK�0�1�2z(%s: netplan does not support accept_ra=2z#%s: unexpected accept_ra value "%s"z%s: method %s is not supportedzetc/network/interfaces�versionzetc/netplan/10-ifupdown.yaml�xzC%s already exists; remove it if you want to run the migration again�zmigration complete, wrote %sz>ifupdown does not configure any interfaces, nothing to migratez#renaming %s to %s.netplan-convertedz.netplan-converted)(�parse_ifupdown�root_dirrr r!�strr"r#�items�debug�
setdefaultrr(�join�keysr%�set�intersectionr�	ipaddress�IPv4Address�AddressValueError�IPv4Network�NetmaskValueError�	prefixlen�IPv6Address�IPv6Network�os�path�yaml�dump�dry_run�print�makedirs�dirname�FileExistsError�open�write�info�rename)r
�netplan_config�ifaces�auto_ifaces�er$�
family_config�family�config�c�supported_opts�unsupported_opts�opts�bad_opts�unsupported�unknown�	addr_spec�net_spec�ipaddr�a�ipnetr�netplan_yaml�dest�frrrr/xsL��
�




�
����$�
�
����$


�
���(

����
�zNetplanMigrate.command_migratec
Cs\dd�}g}t|�d}z�t|d|��}}t�d|j�|D]i}|��}|r,|�d�r-q|�d�rat�d�}||t	j
�|j�|�}	t	�|	�D]}|�
|�r_||�|t	j
�|	|d	�|��7}qGq|�d
�r�t||t	j
�|j�|��D]}||�|||d	��7}qsq|�|�qWd	�W|S1s�wYW|Sty�t�d||�Y|Sw)zvReturn normalized lines from ifupdown config

        This resolves "source" and "source-directory" includes.
        cSs*|��d}|�d�r||S|d|S)Nr,rH)r�
startswith)�rootdir�curdir�line�argrrr�expand_source_argGs
zCNetplanMigrate._ifupdown_lines_from_file.<locals>.expand_source_argr,rHz
reading %s�#zsource-directory z^[a-zA-Z0-9_-]+$Nzsource z%s/%s does not exist, ignoring)�lenrqr rZ�name�stripr��re�compilerhriro�listdir�match�_ifupdown_lines_from_filer\r�append�FileNotFoundError)
r
r�rir��lines�rootdir_lenr�r��valid_re�drrrr�Bs@


"��
������z(NetplanMigrate._ifupdown_lines_from_filerHc	Cs�ddddddd�}|�|d�}t�}t�}d}d}|D]�}|��}	z||	d}
t�d|	|
�d}d}Wn,ty`|rXt�d||�|jdd	�d|||d
|	d<Yqtd|	d��wt|	�|
dkrxtd|
|	dt|	�df��|	dd
vr�|�	|	d�q|	ddkr�td��|	ddkr�q|	ddkr�|	ddvr�td|	d��|	ddvr�td|	d��|	d}|	d}|	did�|�
|	dt��|<qtd|	d��t�d||�||fS)uWParse ifupdown configuration.

        Return (iface_name →  family → {method, options}, auto_ifaces: set) tuple
        on successful parsing, or a ValueError when encountering an invalid file or
        ifupdown features which are not supported (such as "mapping").

        options is itself a dictionary option_name → value.
        r,rU)�auto�
allow-auto�
allow-hotplug�mapping�
no-scriptsr$z/etc/network/interfacesNrz$line fields %s (expected length: %i)z$in_options %s, parsing as option: %s)�maxsplitr;zUnknown stanza type %sz0Expected %i fields for stanza type %s but got %i)r�r�r�r�zmapping stanza is not supportedr�r$r)r<r>zUnknown address family %s)r7r@r8zUnsupported method %s)r6r;z!stanza type %s is not implementedz,final parsed interfaces: %s; auto ifaces: %s)r�rr^rr rZ�KeyErrorrr��addr[�NotImplementedError)r
r��fieldlenr�rvr��
in_options�	in_familyr��fields�exp_lenrrrrVhsR
$�
�"zNetplanMigrate.parse_ifupdown)rH)�__name__�
__module__�__qualname__rrr%r(r4r/r�rV�
__classcell__rrrrr$sK&r)�__doc__r rhr"r�rrjr2�ImportError�collectionsrr`�netplan.cli.utils�cli�utils�NetplanCommandrrrrr�<module>s �

Anon7 - 2022
AnonSec Team