File manager - Edit - /usr/local/cpanel/base/frontend/jupiter/cpguard/directadmin/user/index.raw
Back
#!/opt/cpguard/cpg-php-fpm/bin/php <?php // --------------------------------------------------------------------- // 1. Rebuild $_GET and $_POST from the DirectAdmin environment // --------------------------------------------------------------------- function filter_request_array($array) { $return = []; foreach ($array as $key => $value) { if (is_array($value)) { $return[urldecode($key)] = filter_request_array($value); } else { $return[urldecode($key)] = filter_var(urldecode($value)); } } return $return; } $_GET = []; $query_string = getenv('QUERY_STRING'); if (!empty($query_string)) { parse_str(html_entity_decode($query_string), $get_array); $_GET = filter_request_array($get_array); } $_POST = []; $post_string = getenv('POST'); if (!empty($post_string)) { parse_str(html_entity_decode($post_string), $post_array); $_POST = filter_request_array($post_array); } // --------------------------------------------------------------------- // 2. Define base directories // --------------------------------------------------------------------- $base_dir = realpath(dirname(__DIR__) . '/cpguard'); // Application root $user_dir = getenv('HOME') . '/.cpguard'; // Per-user storage // Safety: if base_dir resolution fails, bail out early if ($base_dir === false) { echo "HTTP/1.1 500 Internal Server Error\n"; echo "Content-Type: text/html; charset=utf-8\n\n"; echo "<h2>Configuration error</h2>"; echo "<p>cPGuard base directory not found.</p>"; exit; } // --------------------------------------------------------------------- // 3. Helper: constrain paths to a base directory // --------------------------------------------------------------------- /** * @param string $base_dir * @param string $requested_file * @return string|false */ function get_safe_path($base_dir, $requested_file) { $base_dir_real = realpath($base_dir); if ($base_dir_real === false) { return false; } // Normalize requested file (strip leading slashes) $requested_file = ltrim($requested_file, '/\\'); $path = $base_dir_real . DIRECTORY_SEPARATOR . $requested_file; $real_path = realpath($path); if ($real_path === false) { return false; } // Ensure $real_path is inside $base_dir_real $base_with_sep = $base_dir_real . DIRECTORY_SEPARATOR; if (strpos($real_path, $base_with_sep) !== 0) { return false; } return $real_path; } // --------------------------------------------------------------------- // 4. File download branch (?file=...) // --------------------------------------------------------------------- if (isset($_GET['file'])) { $safe_path = get_safe_path($user_dir, $_GET['file']); if ($safe_path && is_file($safe_path)) { $mime = mime_content_type($safe_path) ?: 'application/octet-stream'; $fname = basename($safe_path); echo "HTTP/1.1 200 OK\n"; echo "Content-Type: {$mime}\n"; echo "Content-Disposition: attachment; filename=\"{$fname}\"\n"; echo "Cache-Control: max-age=0\n\n"; echo file_get_contents($safe_path); } else { echo "HTTP/1.1 404 Not Found\n"; echo "Content-Type: text/plain; charset=utf-8\n\n"; echo "File not found.\n"; } exit; } // --------------------------------------------------------------------- // 5. UI script branch (?script=...) – default to index.live.php // --------------------------------------------------------------------- $script = $_GET['script'] ?? 'index.live.php'; // Resolve script within $base_dir $safe_path = get_safe_path($base_dir, $script); if (!$safe_path || !is_file($safe_path)) { echo "HTTP/1.1 404 Not Found\n"; echo "Content-Type: text/html; charset=utf-8\n\n"; echo "<h2>Not found</h2>"; echo "<p>The requested script could not be located.</p>"; exit; } // From here on, we serve HTML UI echo "HTTP/1.1 200 OK\n"; echo "Content-Type: text/html; charset=utf-8\n\n"; // Optional: flag for your UI to know it's running from DA raw plugin $directadmin = true; // If your UI expects to run from its application root: chdir($base_dir); // Include your application script (e.g. index.live.php) require_once $safe_path;
| ver. 1.4 |
Github
|
.
| PHP 8.1.34 | Generation time: 0.04 |
proxy
|
phpinfo
|
Settings