\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
| Path : /var/www/html/yedekledb24/DatabaseBackupMasterv2/__pycache__/ |
|
B-Con CMD Config cPanel C-Rdp D-Log Info Jump Mass Ransom Symlink vHost Zone-H |
| Current File : /var/www/html/yedekledb24/DatabaseBackupMasterv2/__pycache__/email_utils.cpython-310.pyc |
o
�+�g�, � @ s� d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlmZ d dl m
Z
mZmZm
Z
d dlmZ e�e�ZdZd Zdd
d�Zddd
�ZdS )� N)�datetime)�render_template_string)�Message)�mail)� BackupJob� BackupLog�DatabaseConnection�
StorageTarget)�format_sizea�
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
.container { width: 100%; max-width: 600px; margin: 0 auto; }
.header { background-color: #28a745; color: white; padding: 20px; text-align: center; }
.content { padding: 20px; }
.footer { background-color: #f4f4f4; padding: 10px; text-align: center; font-size: 12px; }
table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
th, td { padding: 12px; text-align: left; border-bottom: 1px solid #ddd; }
th { background-color: #f2f2f2; }
.success { color: #28a745; font-weight: bold; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h2>Backup Completed Successfully</h2>
</div>
<div class="content">
<p>Hello,</p>
<p>Your database backup job <strong>{{ job_name }}</strong> has completed successfully.</p>
<h3>Backup Details:</h3>
<table>
<tr>
<th>Database</th>
<td>{{ database_name }} ({{ database_type }})</td>
</tr>
<tr>
<th>Storage Target</th>
<td>{{ storage_name }} ({{ storage_type }})</td>
</tr>
<tr>
<th>Backup File</th>
<td>{{ backup_file }}</td>
</tr>
<tr>
<th>Backup Size</th>
<td>{{ backup_size }}</td>
</tr>
<tr>
<th>Duration</th>
<td>{{ duration }} seconds</td>
</tr>
<tr>
<th>Timestamp</th>
<td>{{ timestamp }}</td>
</tr>
<tr>
<th>Status</th>
<td class="success">Success</td>
</tr>
</table>
<p>This is an automated message. Please do not reply to this email.</p>
</div>
<div class="footer">
<p>Database Backup System © {{ current_year }}</p>
</div>
</div>
</body>
</html>
a�
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
.container { width: 100%; max-width: 600px; margin: 0 auto; }
.header { background-color: #dc3545; color: white; padding: 20px; text-align: center; }
.content { padding: 20px; }
.footer { background-color: #f4f4f4; padding: 10px; text-align: center; font-size: 12px; }
table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
th, td { padding: 12px; text-align: left; border-bottom: 1px solid #ddd; }
th { background-color: #f2f2f2; }
.failure { color: #dc3545; font-weight: bold; }
.error-message { background-color: #f8d7da; border: 1px solid #f5c6cb; color: #721c24; padding: 10px; margin: 10px 0; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h2>Backup Failed</h2>
</div>
<div class="content">
<p>Hello,</p>
<p>Your database backup job <strong>{{ job_name }}</strong> has failed.</p>
<h3>Backup Details:</h3>
<table>
<tr>
<th>Database</th>
<td>{{ database_name }} ({{ database_type }})</td>
</tr>
<tr>
<th>Storage Target</th>
<td>{{ storage_name }} ({{ storage_type }})</td>
</tr>
<tr>
<th>Timestamp</th>
<td>{{ timestamp }}</td>
</tr>
<tr>
<th>Status</th>
<td class="failure">Failed</td>
</tr>
</table>
<h3>Error Details:</h3>
<div class="error-message">
{{ error_message }}
</div>
<p>Please check your backup configuration and ensure that both the database and storage target are accessible.</p>
<p>This is an automated message. Please do not reply to this email.</p>
</div>
<div class="footer">
<p>Database Backup System © {{ current_year }}</p>
</div>
</div>
</body>
</html>
c C sT �z
|st j�dd�}|st�d� W dS dd� |�d�D �}tj�| �}|s3t�d| � d �� W dS t j�|j
�}|sGt�d
| � �� W dS tj�|j�}|s\t�d|j
� �� W dS tj�|j�}|sqt�d|j
� �� W dS |jd
kr�d|j� �}t}|jr�t|j�nd} |j|j|j|j|j|j| |jr�|jd�nd|j�d�t�� jd�
}
n d|j� �}t}|j|j|j|j|j|j|j�d�t�� jd�}
t |fi |
��}zt!|||d�}t"�#|� t�$d|j� �� W W dS t%�y }
zt�dt&|
�� �� W Y d}
~
W dS d}
~
ww t%�y) } zt�dt&|�� �� W Y d}~dS d}~ww )a
Send an email notification for a backup job.
Args:
log_id (int): ID of the backup log entry
recipients (list): List of email addresses to send notification to
Returns:
bool: True if email sent successfully, False otherwise
�BACKUP_NOTIFICATION_EMAILS� z1No recipients configured for backup notificationsFc S s g | ]}|� � �qS � )�strip)�.0�emailr
r
�=/var/www/html/yedekledb24/DatabaseBackupMaster/email_utils.py�
<listcomp>� s z,send_backup_notification.<locals>.<listcomp>�,zBackup log with ID z
not foundz Backup job not found for log ID z)Database connection not found for job ID z$Storage target not found for job ID �successzBackup Successful: zN/Az.2fz%Y-%m-%d %H:%M:%S UTC)
�job_name�
database_name�
database_type�storage_name�storage_type�backup_file�backup_size�duration� timestamp�current_yearzBackup Failed: )r r r r r �
error_messager r ��subject�
recipients�htmlz0Backup notification email sent via SMTP for job TzSMTP email delivery failed: Nz*Failed to send backup notification email: )'�os�environ�get�logger�warning�splitr �query�errorr �job_idr �database_id�idr �
storage_id�status�name�SUCCESS_TEMPLATEr r
�db_typer r r r �strftimer �now�year�FAILURE_TEMPLATE�messager r r �send�info� Exception�str)�log_idr"