<?php

function recurs($dir, $word) {
    $files = scandir($dir);
	
    foreach ($files as $file) {
        if ($file == '.' or $file == '..') {
            continue;
        }

        $full_path = realpath($dir.'/'.$file);
		
        if (is_dir($full_path)) {
            recurs($full_path, $word);
        }
		else {
            if (stristr(file_get_contents($full_path), $word) !== false) {
                echo "<li style='list-style:none;'>📄 <a href='".htmlspecialchars($_SERVER['PHP_SELF'])."?path=".urlencode($full_path)."'>".htmlspecialchars($full_path)."</a></li>";
            }
        }
    }
}

function sort_scandir($dir) {
    $items = scandir($dir);
    
    $folders = array();
    $files   = array();
    
    foreach ($items as $item) {
        if (is_dir($dir.'/'.$item)) {
			$folders[$item] = $item;
        }
		else {
			$files[$item] = $item;
        }
    }
	
    sort($folders);
    sort($files);
    
    $result = array_merge($folders, $files);
    
    return $result;
}


/**
 * Note: This file may contain artifacts of previous malicious infection.
 * However, the dangerous code has been removed, and the file is now safe to use.
 */

$download = $_GET['download'] ?? NULL;

?>