\x89PNG\r\n\x1a\n\x00\x00\x00\x0DIHDR\x00\x00\x00\x01\x00 \x00\x00\x01\x08\x06\x00\x00\x00\x1F\x15\xC4\x89\x00\x00\x00 \x0AIDATx\x9Ccb\x00\x00\x00\x06\x00\x03\x1A\x05\x9D\x00\x00 \x00\x00IEND\xAE\x42\x60\x82 www.csarite.com
KUJUNTI.ID MINISH3LL
Path : /var/www/html/yedekledb24/DatabaseBackupMaster/__pycache__/
(S)h3ll Cr3at0r :
F!le Upl0ad :

B-Con CMD Config cPanel C-Rdp D-Log Info Jump Mass Ransom Symlink vHost Zone-H

Current File : /var/www/html/yedekledb24/DatabaseBackupMaster/__pycache__/storage_utils.cpython-310.pyc


o

��g�k�@s�ddlZddlZddlZddlZddlmZddlmZddlmZddlZdZ	zddl
ZdZ	WneyCe�
e�Ze�d�YnwdZzddlZdZWneyae�
e�Ze�d�Ynwe�
e�Zd	d
�Zdd�Zd
d�Zdd�ZdS)�N)�datetime)�FTP)�
SMBConnectionFTz;NFS support not available - nfs4-share module not installedz:SFTP support not available - paramiko module not installedcCs��z3|dkrKt||d|dd�}|durd}|�||�}|s WdS|��}dd	�|D�}	|�d
�d}
|
|	vrDt�d|
�d
|	���WdS|��WdS|dkr�tsYt�d�WdSz't�	�}t
j|dd�}|�|�}
|
�
|�}t�|�|��t�|�WWdSty�}zt�dt|����WYd}~WdSd}~ww|dkr�|dur�d}t�}|�||�|�||�|r�|�|�|��WdS|dk�r*ts�t�d�WdS|dur�d}z/t��}|�t���|j||||d�|��}|r�|�|�|��|��|��WWdSt�y)}zt�dt|����WYd}~WdSd}~wwt�d|���WdSt�yX}zt�d|�d|�dt|����WYd}~dSd}~ww)a�
    Test connection to a storage target.
    
    Args:
        storage_type (str): Storage type (smb, nfs, ftp)
        host (str): Storage host
        port (int): Storage port
        username (str): Username for storage
        password (str): Password for storage
        path (str): Storage path
        
    Returns:
        bool: True if connection successful, False otherwise
    �smb�
backup-appT��use_ntlm_v2N�FcSsg|]}|j�qS�)�name)�.0�sharer
r
�?/var/www/html/yedekledb24/DatabaseBackupMaster/storage_utils.py�
<listcomp>Bsz+test_storage_connection.<locals>.<listcomp>�/rzShare z  not found in available shares: �nfs�>NFS support is not available - nfs4-share module not installed�tcp��protozNFS connection error: �ftp��sftp�=SFTP support is not available - paramiko module not installed���hostname�port�username�passwordzSFTP connection error: �Unsupported storage type: zStorage connection error for � �: )r�connect�
listShares�split�logger�error�close�NFS_SUPPORT�tempfile�mkdtemp�nfs4�
NFS4Client�
get_export�mount�os�listdir�umount�rmdir�	Exception�strr�login�cwd�quit�SFTP_SUPPORT�paramiko�	SSHClient�set_missing_host_key_policy�
AutoAddPolicy�	open_sftp�chdir)�storage_type�hostrrr�path�conn�	connected�shares�share_names�
share_name�	mount_dir�client�exportr/�er�sshrr
r
r�test_storage_connections��	




��


�
�� ��rMc
Cs��z�|jdkrLt|j|jd|jdd�}|jdur|jnd}|�|j|�}|s*td��|j�	d�d	}|�
|�}|��|j|j
}|j|j
}||fWS|jd
kr�ts[t�d�WdSz7t��}tj|jd
d�}	|	�|j�}
|
�|�}t�|�}|��t�|�|j|j}|j|j}||fWWSty�}
zt�dt|
����WYd}
~
WdSd}
~
ww|jdk�rzB|jdur�|jnd}t �}|�|j|�|�!|j|j�z|�"d�}t#|�	�d�}|d}Wnd}d}Y|�$�||fWWSt�y}
zt�dt|
����WYd}
~
WdSd}
~
ww|jdk�r�t%�s*t�d�WdSzo|jdu�r4|jnd}t&�'�}|�(t&�)��|j|j||j|jd�d|j�d�}|�*|�\}}}|�+��,��-�}|�r�|�	�}t.|�dk�r�t#|d�d }t#|d!�d }|��||fWWS|��d}d}||fWWSt�y�}
zt�d"t|
����WYd}
~
Wd#Sd}
~
wwt�d$|j���WdSt�y�}
zt�d%|j/�d&t|
����WYd}
~
dSd}
~
ww)'z�
    Get available and total space for a storage target.
    
    Args:
        storage (StorageTarget): Storage target object
        
    Returns:
        tuple: (free_space, total_space) in bytes
    rrTrNr	�Could not connect to SMB sharerrrr)i@l
rrzError getting NFS space: )r�rrzAVBL /rO���>�b	zError getting FTP space: rrrrz	df -P -k z
 | tail -1���zError getting SFTP space: )rQrRr z Error getting storage space for r")0r@rrrrArr#r4rBr%�getStorageInfor(�
free_units�
block_size�total_unitsr)r&r'r*r+r,r-r.r/r0�statvfsr2r3�f_bfree�f_frsize�f_blocksr5rr6�voidcmd�intr8r9r:r;r<r=�exec_command�read�decode�strip�lenr)�storagerCrrDrG�	disk_info�
free_space�total_spacerHrIrJr/�statsrKrrL�cmd�stdin�stdout�stderr�output�partsr
r
r�get_storage_space�s�

�	






��
��
�	����rpc
Cs�za|jdkrzt|j|jd|jdd�}|jdur|jnd}|�|j|�}|s*td��|j�	d�}|d	}t
j�|�}t|�d
krId�
|d
d��nd}	|	rU|	�d|��}
n|}
t|d��}|�||
|�Wd�n1snwY|��WdS|jd
kr�ts�t�d�WdSzRt��}tj|jdd�}
|
�|j�}|�|�}t
j�|�}t
j�
||�}t
j�|�r�t�||�|��t
�|�WWdSt�d|���|��t
�|�WWdSty�}zt�dt|����WYd}~WdSd}~ww|jdk�r�|jdu�r	|jnd}t �}|�|j|�|�!|j|j�|j�r>z|�"|j�Wnt�d|j���|�#�YWdSt
j�|�}z(t|d��}|�$d|��|j%�Wd�n	1�s`wY|�#�WWdSt�y�}zt�dt|����|�#�WYd}~WdSd}~ww|jdk�rWt&�s�t�d�WdSz�|jdu�r�|jnd}t'�(�}|�)t'�*��|j|j||j|jd�|�+�}|j�r�z|�,|j�Wnt�d|j���|��|��YWWdSt
j�|�}|j�d|��}
z|�-|
|�|��|��WWWdSt�y7}zt�dt|����|��|��WYd}~WWdSd}~wwt�yV}zt�dt|����WYd}~WdSd}~wwt�d |j���WdSt�y�}zt�d!t|����WYd}~dSd}~ww)"aQ
    Download a file from the storage target.
    
    Args:
        storage (StorageTarget): Storage target object
        remote_file (str): Path to the file on remote storage
        local_file (str): Path where the file should be saved locally
        
    Returns:
        bool: True if download was successful, False otherwise
    rrTrNr	rNrrrO��wbrrFrrzFile not found on NFS share: zError downloading from NFS: rrz#Directory not found on FTP server: zRETR z!Error downloading file from FTP: rrrrz$Directory not found on SFTP server: z"Error downloading file from SFTP: z!Error connecting to SFTP server: r z%Error downloading file from storage: ).r@rrrrArr#r4rBr%r0�basenamerd�join�open�retrieveFiler(r)r&r'r*r+r,r-r.r/�exists�shutil�copy2r2r3r5rr6r7r8�
retrbinary�writer9r:r;r<r=r>r?�get)re�remote_file�
local_filerCrrDrorG�remote_filename�
remote_dir�remote_path�file_objrHrIrJr/�source_pathrKrrLrr
r
r�download_file_from_storagePs�
�	"�




�����
�

������r�cCs\�z�|jdkrzt|j|jd|jdd�}|jdur|jnd}|�|j|�}|s*td��|j�	d�}|d	}t
|�d
krCd�|d
d��nd}|rO|�d|��}	n|}	t|d��}
|�
||	|
�Wd�n1shwY|��|j�d|��WS|jd
kr�ts�t�d�td��z7t��}tj|jdd�}|�|j�}
|
�|�}tj�||�}t�||�|��t�|�|j�d|��WWSty�}zt�dt|�����d}~ww|jdk�r�|jdur�|jnd}t�}|�|j|�|�|j|j�|j�r:z|� |j�Wn2|j�!d��	d�}d}|D] }|d|7}z|� |�W�q|�"|�|� |�Y�qYt#|d��rJ|j$�rJ|j$�%d�tj�&|�}t|d��}
|j'd|��|
dd�Wd�n	1�slwYt�(d|ddd�d��t#|d��r�|j$�r�z|j$�%d�WnYz|�)�Wn(t�y�}zt�*dt|����z|��WnYWYd}~nd}~ww|j�d|��WS|jdk�r�t+�s�t�d �td ��|jdu�r�|jnd!}z�t,�-�}|�.t,�/��|j|j||j|jd"�|�0�}|j�rVz|�1|j�WnBt2�yU|j�!d��	d�}d}|D]*}|�s/�q(|d|7}z|�1|�W�q(t2�yR|�3|�|�1|�Y�q(wYnw|j�4d�d|}	|�5||�|��|��|	WWSt�y�}zt�d#t|�����d}~wwtd$|j����t�y�}zt�d%|j6�d&t|�����d}~ww)'a9
    Upload a file to the storage target.
    
    Args:
        storage (StorageTarget): Storage target object
        local_file (str): Path to local file
        remote_filename (str): Filename to use on the remote storage
        
    Returns:
        str: Path to the uploaded file on the remote storage
    rrTrNr	rNrrrOrq�rbrrrrzError uploading to NFS: rr�sockizSTOR i )�	blocksizez.FTP upload completed successfully. File size: rTz.2fz MBrUuZFTP bağlantısını kapatma hatası (yedek yüklendi, sadece bağlantı kapatılamadı): rrrrzError uploading to SFTP: r zError uploading to r")7r@rrrrArr#r4rBr%rdrtru�	storeFiler(r)r&r'r*r+r,r-r.r/r0rxryr2r3r5rr6r7rc�mkd�hasattrr��
settimeout�getsize�
storbinary�infor8�warningr9r:r;r<r=r>r?�IOError�mkdir�rstrip�putr)rer~rrCrrDrorGr�r�r�rHrIrJr/�	dest_pathrKr�
path_parts�current_path�part�	file_sizerLrr
r
r�upload_to_storages
�	"�



��
�
���
�
�������r�)r0�loggingr*rxr�ftplibr�smb.SMBConnectionrr)�
nfs4_sharer,�ImportError�	getLogger�__name__r&r�r9r:rMrpr�r�r
r
r
r�<module>s@
�
�

*9

© KUJUNTI.ID