\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/yedekle24/BackupShield/ |
|
B-Con CMD Config cPanel C-Rdp D-Log Info Jump Mass Ransom Symlink vHost Zone-H |
| Current File : /var/www/html/yedekle24/BackupShield/utils.py |
import os
import re
import sys
import smtplib
import socket
import requests
import datetime
import time
import ssl
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
# Try to load environment variables if dotenv is available
try:
from dotenv import load_dotenv
load_dotenv()
except ImportError:
pass # dotenv is not required if environment variables are set elsewhere
# Sabit SMTP ayarları (doğrudan kodun içine gömülü)
SMTP_HOST = 'mail.hepsibulutta.com'
SMTP_PORT = 587
SMTP_USER = 'yedekle24@hepsibulutta.com'
SMTP_PASSWORD = 'ooka5asd2mas2el1ai0eeC222'
FROM_EMAIL = 'yedekle24@hepsibulutta.com'
TO_EMAIL = 'gokhana@ofisbulutta.com'
SECOND_TO_EMAIL = 'arsiv@arsiv.ofisbulutta.tr'
def is_valid_email(email):
"""
Validate an email address using a regex pattern.
Args:
email (str): Email address to validate
Returns:
bool: True if the email is valid, False otherwise
"""
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
return re.match(pattern, email) is not None
def verify_recaptcha(recaptcha_response):
"""
Verify a reCAPTCHA response with Google's API.
Args:
recaptcha_response (str): reCAPTCHA response token
Returns:
bool: True if verification successful, False otherwise
str: Error message if verification failed, empty string otherwise
"""
secret_key = os.environ.get('RECAPTCHA_SECRET_KEY')
if not secret_key:
print("Error: RECAPTCHA_SECRET_KEY is not set in environment variables")
return False, "reCAPTCHA configuration error on server"
if not recaptcha_response:
return False, "reCAPTCHA response is required"
try:
verification_url = 'https://www.google.com/recaptcha/api/siteverify'
payload = {
'secret': secret_key,
'response': recaptcha_response
}
response = requests.post(verification_url, data=payload)
result = response.json()
print(f"reCAPTCHA verification response: {result}")
if result.get('success'):
return True, ""
else:
error_codes = result.get('error-codes', [])
error_message = "reCAPTCHA verification failed"
if error_codes:
error_message += f": {', '.join(error_codes)}"
return False, error_message
except Exception as e:
print(f"reCAPTCHA verification error: {e}")
return False, "Error connecting to reCAPTCHA service"
def send_contact_email(name, email, subject, message):
"""
Send an email from the contact form using SMTP settings.
Args:
name (str): Sender's name
email (str): Sender's email
subject (str): Email subject
message (str): Email message body
Returns:
tuple: (success, error_message)
- success (bool): True if email was sent successfully, False otherwise
- error_message (str): Error message if sending failed, empty string otherwise
"""
try:
# Validate email format
if not is_valid_email(email):
return False, "Invalid email format"
# Dinamik değerler
current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
# Create message body
body = f"""
İletişim Formu Mesajı:
Ad Soyad: {name}
E-posta: {email}
Konu: {subject}
Mesaj:
{message}
---
Bu e-posta YedekleDB24 iletişim formundan gönderilmiştir.
Tarih/Saat: {current_time}
"""
# Debug output
print(f"Connecting to SMTP server: {SMTP_HOST}:{SMTP_PORT}")
print(f"Using credentials: {SMTP_USER}")
print(f"From: {FROM_EMAIL}")
print(f"To: {TO_EMAIL}")
# Create message with MIMEMultipart
msg = MIMEMultipart()
msg['From'] = FROM_EMAIL
msg['To'] = TO_EMAIL
msg['Subject'] = f"YedekleDB24 İletişim Formu: {subject}"
# Add reply-to header with sender information
msg['Reply-To'] = f"{name} <{email}>"
# Attach message body
msg.attach(MIMEText(body, 'plain'))
# Create secure connection
context = ssl.create_default_context()
# Connect to server and send email
with smtplib.SMTP(SMTP_HOST, SMTP_PORT, timeout=30) as smtp:
print("Connected to server")
smtp.ehlo()
print("EHLO successful")
smtp.starttls(context=context)
print("TLS started")
smtp.ehlo() # Re-identify after TLS
print("EHLO after TLS successful")
smtp.login(SMTP_USER, SMTP_PASSWORD)
print("Login successful")
print("Attempting to send contact form email...")
smtp.send_message(msg)
print("Contact form email sent successfully!")
# Attempt to send to second recipient
try:
time.sleep(2) # Wait a bit before sending to the second recipient
print(f"\nAttempting to send to second recipient: {SECOND_TO_EMAIL}")
msg['To'] = SECOND_TO_EMAIL
smtp.send_message(msg)
print(f"Email also sent to second recipient: {SECOND_TO_EMAIL}")
except Exception as e:
print(f"Note: Could not send to second recipient, but primary email was sent. Error: {e}")
# Continue since we already sent to the primary recipient
return True, ""
except Exception as e:
error_message = f"Email Error: {str(e)}"
print(f"Error: {error_message}")
import traceback
traceback.print_exc()
return False, error_message
def send_email_via_smtp(from_email=None, to_email=None, subject="", body_text="", sender_name=None, sender_email=None):
"""
Send an email using direct SMTP connection.
Args:
from_email (str, optional): Email address to send from, uses default if None
to_email (str, optional): Email address to send to, uses default if None
subject (str): Email subject
body_text (str): Email body text
sender_name (str, optional): Original sender's name
sender_email (str, optional): Original sender's email
Returns:
tuple: (success, error_message)
"""
try:
# Use the global SMTP settings or default to provided values
actual_from_email = from_email or FROM_EMAIL
actual_to_email = to_email or TO_EMAIL
# Debug output
print(f"Connecting to SMTP server: {SMTP_HOST}:{SMTP_PORT}")
print(f"Using credentials: {SMTP_USER}")
print(f"From: {actual_from_email}")
print(f"To: {actual_to_email}")
# Create message
msg = MIMEMultipart()
msg['From'] = actual_from_email
msg['To'] = actual_to_email
msg['Subject'] = subject
# Add reply-to header if sender information is provided
if sender_name and sender_email:
msg['Reply-To'] = f"{sender_name} <{sender_email}>"
# Attach message body
msg.attach(MIMEText(body_text, 'plain'))
# Create secure connection
context = ssl.create_default_context()
# Connect to server
with smtplib.SMTP(SMTP_HOST, SMTP_PORT, timeout=30) as smtp:
print("Connected to server")
smtp.ehlo()
print("EHLO successful")
smtp.starttls(context=context)
print("TLS started")
smtp.ehlo() # Re-identify after TLS
print("EHLO after TLS successful")
smtp.login(SMTP_USER, SMTP_PASSWORD)
print("Login successful")
print("Attempting to send email...")
smtp.send_message(msg)
print("Email sent successfully!")
return True, ""
except Exception as e:
error_message = f"SMTP Error: {str(e)}"
print(f"Error: {error_message}")
import traceback
traceback.print_exc()
return False, error_message
# Kullanıcının isteği üzerine SendGrid kaldırıldı