Hacked By AnonymousFox

Current Path : /opt/cloudlinux/venv/lib64/python3.11/site-packages/ssa/internal/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/ssa/internal/__pycache__/mailer.cpython-311.pyc

�

qu�f�����dZddlZddlZddlZddlZddlmZmZddlm	Z	ddl
mZddlm
Z
ddlmZmZddlmZd	d
lmZd	dlmZd	dlmZmZd
�Zdedefd�ZGd�d��ZdS)z8
This module contains SSA Mailer class and helper tools
�N)�ConfigParser�SectionProxy)�EmailMessage��gethostname)�is_cl_solo_edition)�Environment�FileSystemLoader��get_ip_addr�)�mail_template_location)�SSAMailerError)�
duration_cast�format_datec�$�t|��pdS)N�UNKNOWNr)�hostnames �J/opt/cloudlinux/venv/lib64/python3.11/site-packages/ssa/internal/mailer.py�_get_server_iprs���x� � �-�I�-��report_data�returnc��ttt��dd���}t|jd<|�d��}|�|dtd������}|�d��}t��}|�t|d	��||t|���
��}||fS)zJ
    Render an HTML table for e-mail report and a full e-mail message
    T)�loader�trim_blocks�
lstrip_blocksrzreport_table.html�domains)�skip_jwt_check)r�is_soloz	mail.html�date)r!�report_tabler�ip_addr)r	r
rr�filters�get_template�renderrrrr)r�env�table_templater"�
mail_templater�mails       r�render_report_tabler+s����� 6�7�7������C�
$1�C�K�� ��%�%�&9�:�:�N�!�(�(��Y�1G�1C�<@�2B�2B�2B�)�C�C�L�
�$�$�[�1�1�M��}�}�H����[��V�1D�%E�%E�-9�)1�(6�x�(@�(@� �B�B�D����rc���eZdZdZd�Zedefd���Zedefd���Z	e
dedefd���Zde
dd	fd
�Zde
dd	fd�Zde
dd	fd
�Z	ddededd	fd�Zdedede
fd�Zd	S)�Mailerz.
    Class contains SSA e-mail send logic
    c�F�tjd��|_d|_dS)N�mailer)�logging�	getLogger�logger�_sender��selfs r�__init__zMailer.__init__>s���'��1�1�������rrc��dS)z+
        Local mail server address
        )�	localhost�r4s r�mail_serverzMailer.mail_serverBs	��
�~rc�$�dt����S)z%
        'From' mail address
        zslow-site-analyzer@rr4s r�senderz
Mailer.senderIs��
5�[�]�]�4�4�4r�namec���t�d|�d�}tj�|��r-t	d���}|�|��|dSt
d|�dt�����)zF
        Get preformatted data for e-mail by name of template
        �/z.iniN)�
interpolation�datazFailed to find template z in )r�os�path�existsr�readr)r=�tmpl�configs   r�
read_templatezMailer.read_templatePs���
)�5�5�4�5�5�5��
�7�>�>�$���	"�!��5�5�5�F��K�K������&�>�!��I�t�I�I�1G�I�I�K�K�	Kr�messageNc���|j�d��	tj|j�5}|�|��}|j�d|��ddd��dS#1swxYwYdS#tj$r$}tdt|�������d}~wttf$r$}tdt|�������d}~wwxYw)z=
        Send preformatted e-mail via localhost SMTP
        zTry to send via smtpzSend result: %sNzsmtp mailing failed: zsmtp connection failed: )r2�info�smtplib�SMTPr:�send_message�
SMTPExceptionr�str�ConnectionError�OSError)r5rI�server�result�es     r�
_smtp_sendzMailer._smtp_send]s>��	
����/�0�0�0�	F���t�/�0�
<�F��,�,�W�5�5���� � �!2�F�;�;�;�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<����
<�
<�
<�
<�
<�
<���$�	C�	C�	C� �!A��Q���!A�!A�B�B�B�������)�	F�	F�	F� �!D�C��F�F�!D�!D�E�E�E�����	F���sF�A:�1A-� A:�-A1�1A:�4A1�5A:�:C �	B(�(C �<C�C c� �|j�d��gd�}	tj||���ddd���dS#t
ttjf$r$}tdt|�������d}~wwxYw)z?
        Send preformatted e-mail via sendmail utility
        z Try to send via sendmail utility)z/usr/sbin/sendmailz-tz-oiT)�input�capture_output�text�checkzsendmail utility failed with N)
r2rK�
subprocess�run�	as_stringrR�
ValueError�CalledProcessErrorrrP)r5rI�cmdrUs    r�
_console_sendzMailer._console_sendks���	
����;�<�<�<�1�1�1��	K��N�3�!(�!2�!2�!4�!4�*.� $�D�
2�
2�
2�
2�
2�
2����Z�%B�C�	K�	K�	K� �!I��Q���!I�!I�J�J�J�����	K���s�+A
�
B
�)B�B
r*c��	|�|��dS#t$r�}|j�t	|����	|�|��n_#t$rR}|j�t	|����|j�d|d��Yd}~nd}~wwxYwYd}~dSYd}~dSd}~wwxYw)zm
        Try to send mail via localhost smtp server,
        if fails -- try to use sendmail utility
        z3Both smtp and sendmail failed to send message to %s�ToN)rVrr2�errorrPrb�critical)r5r*rUs   r�_sendzMailer._sendys ��

	 ��O�O�D�!�!�!�!�!���	 �	 �	 ��K���c�!�f�f�%�%�%�
 ��"�"�4�(�(�(�(��!�
 �
 �
 ���!�!�#�a�&�&�)�)�)���$�$�I���J� � � � � � � � �����
 ����)�(�(�(�(�(� � � � � � �����
	 ���s?��
C�'C�A!� C�!
B=�+AB8�3C�8B=�=C�C�
ssa_report�	recipient�templatec�J�|�|j||fi|����dS)z{
        Create a message from given template, including additional kwargs,
        and send it to given recipient
        N)rg�_message)r5rirj�kwargss    r�send_simple_mailzMailer.send_simple_mail�s2��	
�
�
�=�4�=��H�?�?��?�?�@�@�@�@�@rc�\�|�|��}t��}|d|z|d<|j|d<||d<|�|d|z��|�|d|zd���|j�d|�����|S)	z 
        Form a message
        �subject�Subject�FromrdrZ�html)�subtypezGenerated mail --> %s)rHrr<�set_content�add_alternativer2rKr^)r5rirjrmrA�msgs      rrlzMailer._message�s����!�!�(�+�+���n�n���i��6�1��I���k��F����D�	�����V��v�-�.�.�.����D��L�6�1�6��B�B�B�����0�#�-�-�/�/�B�B�B��
r)rh)�__name__�
__module__�__qualname__�__doc__r6�property�tupler:rPr<�staticmethodrrHrrVrbrgrnrlr9rrr-r-9s��������������U�����X���5��5�5�5��X�5��
K�C�
K�L�
K�
K�
K��\�
K�F�,�F�4�F�F�F�F�K�\�K�d�K�K�K�K� �,� �4� � � � �&*6�A�A�$'�A�#&�A�'+�A�A�A�A������+������rr-)r{r0rBrLr\�configparserrr�
email.messager�socketr�clcommon.lib.cleditionr�jinja2r	r
�clcommon.lib.networkr�	constantsr�
exceptionsr�utilsrrr�dictr}r+r-r9rr�<module>r�sY��������	�	�	�	���������3�3�3�3�3�3�3�3�&�&�&�&�&�&�������5�5�5�5�5�5�0�0�0�0�0�0�0�0�,�,�,�,�,�,�-�-�-�-�-�-�&�&�&�&�&�&�-�-�-�-�-�-�-�-�.�.�.��T��e�����4m�m�m�m�m�m�m�m�m�mr

Hacked By AnonymousFox1.0, Coded By AnonymousFox