Initial commit

This commit is contained in:
2026-03-26 10:32:29 +01:00
commit 44987dfdba
2 changed files with 68 additions and 0 deletions

19
cert_check.sh Normal file
View File

@@ -0,0 +1,19 @@
#!/bin/bash
script_dir="$(cd "$(dirname "$0")" && pwd)"
cert_valid_for=$(
certbot certificates 2>/dev/null |
grep -A 4 "fm.ines.org.pl" |
grep "Expiry Date" |
awk -F'[()]' '{print $2}' |
awk '{print $2}'
)
cert_valid_for="${cert_valid_for//[^0-9]/}"
cert_valid_for=$((10#${cert_valid_for:-0}))
if (( cert_valid_for < 30 ))
then
python3 "$script_dir/mail.py" --user "certificates@piga.pl" --password 'cgpM!tABM43_meJ' --to "it@piga.pl" --subject "Wygasa certyfikat dla serwera $(hostname)" --body "Certyfikat dla serwera $(hostname) jest ważny jeszcze $cert_valid_for dni."
fi

49
mail.py Normal file
View File

@@ -0,0 +1,49 @@
import argparse
import smtplib
from email.message import EmailMessage
SMTP_HOST = "mail.piga.pl"
SMTP_PORT = 587
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="Wysylka maila przez SMTP mail.piga.pl:587 z STARTTLS."
)
parser.add_argument("--user", required=True, help="Login SMTP, np. user@piga.pl")
parser.add_argument("--password", required=True, help="Haslo do konta SMTP")
parser.add_argument("--to", required=True, dest="recipient", help="Adres odbiorcy")
parser.add_argument("--subject", default="Test SMTP", help="Temat wiadomosci")
parser.add_argument(
"--body",
required=True,
help='Tresc wiadomosci, np. --body "To jest test".',
)
return parser.parse_args()
def build_message(args: argparse.Namespace) -> EmailMessage:
message = EmailMessage()
message["From"] = args.user
message["To"] = args.recipient
message["Subject"] = args.subject
message.set_content(args.body)
return message
def send_mail(args: argparse.Namespace) -> None:
message = build_message(args)
with smtplib.SMTP(SMTP_HOST, SMTP_PORT, timeout=30) as server:
server.ehlo()
server.starttls()
server.ehlo()
server.login(args.user, args.password)
server.send_message(message)
if __name__ == "__main__":
arguments = parse_args()
send_mail(arguments)
print("Mail wyslany poprawnie.")