vegdZddlZddlZddlZddlZddlmZmZddlm Z ddl m Z ddl m Z ddlmZmZddlmZd d lmZd d lmZd d lmZmZd ZdedefdZGddZdS)z8 This module contains SSA Mailer class and helper tools N) ConfigParser SectionProxy) EmailMessage gethostname)is_cl_solo_edition) EnvironmentFileSystemLoader get_ip_addr)mail_template_location)SSAMailerError) duration_cast format_datec$t|pdS)NUNKNOWNr )hostnames J/opt/cloudlinux/venv/lib64/python3.11/site-packages/ssa/internal/mailer.py_get_server_iprs x -I- report_datareturnctttdd}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.htmldomains)skip_jwt_check)ris_soloz mail.htmldate)r! report_tablerip_addr) r r rrfilters get_templaterenderrrrr)renvtable_templater" mail_templatermails rrender_report_tabler+s  677   C $1CK %%&9::N!((Y1G1C<@2B2B2B)CCL $$[11M}}H   [V1D%E%E-9)1(6x(@(@  B BD  rceZdZdZdZedefdZedefdZ e dede fdZ de dd fd Zde dd fd Zd e dd fd Z ddededd fdZdedede fdZd S)Mailerz. Class contains SSA e-mail send logic cFtjd|_d|_dS)Nmailer)logging getLoggerlogger_senderselfs r__init__zMailer.__init__>s'11  rrcdS)z+ Local mail server address ) localhostr4s r mail_serverzMailer.mail_serverBs ~rc$dtS)z% 'From' mail address zslow-site-analyzer@rr4s rsenderz Mailer.senderIs 5[]]444rnamectd|d}tj|r-t d}|||dSt d|dt)zF Get preformatted data for e-mail by name of template /z.iniN) interpolationdatazFailed to find template z in )rospathexistsrreadr)r=tmplconfigs r read_templatezMailer.read_templatePs )554555 7>>$   "!555F KK   &> ! It I I1G I IKK KrmessageNc|jd tj|j5}||}|jd|ddddS#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: ) r2infosmtplibSMTPr: send_message SMTPExceptionrstrConnectionErrorOSError)r5rIserverresultes r _smtp_sendzMailer._smtp_send]s> /000 Ft/0 %s)rHrr< set_contentadd_alternativer2rKr^)r5rirjrmrAmsgs rrlzMailer._messages!!(++nni61IkF D  V v-... DL616BBB 0#--//BBB r)rh)__name__ __module__ __qualname____doc__r6propertytupler:rPr< staticmethodrrHrrVrbrgrnrlr9rrr-r-9sUX 5555X5  KC KL K K K\ K F, F4 F F F F K\ Kd K K K K , 4    &*6AA$'A#&A'+AAAA+rr-)r{r0rBrLr\ configparserrr email.messagersocketrclcommon.lib.cleditionrjinja2r r clcommon.lib.networkr constantsr exceptionsrutilsrrrdictr}r+r-r9rrrsY 33333333&&&&&&55555500000000,,,,,,------&&&&&&--------...Te4mmmmmmmmmmr