&1"; // check if shell_exec available if (!function_exists('shell_exec')) { return ['_raw' => '', 'error' => 'PHP shell_exec() is disabled on this server.']; } $out = shell_exec($full); return ['_raw' => $out, 'cmd' => $full]; } function runUapi($uapiCmd) { // uapi expects: uapi Module func param=... param2=... $res = runCommand("uapi $uapiCmd --output=json"); $out = $res['_raw'] ?? ''; $json = json_decode($out, true); if ($json === null) { return ['_raw' => $out, 'status' => 0, 'errors' => ["Failed to parse JSON"], 'cmd' => $res['cmd'] ?? null]; } return $json; } function runWhmapi1($cmdArgs) { // whmapi1 param=... --output=json $res = runCommand("/usr/local/cpanel/bin/whmapi1 $cmdArgs --output=json"); $out = $res['_raw'] ?? ''; $json = json_decode($out, true); if ($json === null) { return ['_raw' => $out, 'status' => 0, 'errors' => ["Failed to parse JSON from whmapi1"], 'cmd' => $res['cmd'] ?? null]; } return $json; } function getServerIP() { $info = runUapi("Variables get_user_information"); $ip = $info['result']['data']['ip'] ?? ($info['result']['data']['primaryip'] ?? null); if (!$ip) { $raw = trim(shell_exec('hostname -I 2>/dev/null')); if ($raw) { $ips = preg_split('/\s+/', $raw); $ip = $ips[0] ?? $raw; } } return $ip ?: 'Tidak ditemukan'; } function prettyJsonHtml($arr) { return '
' .
           htmlspecialchars(json_encode($arr, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)) .
           '
'; } // ----------------- main logic ----------------- $flash = null; $last_summary = null; $listFtp = []; $info = null; // On POST actions if ($_SERVER['REQUEST_METHOD'] === 'POST') { $action = $_POST['action'] ?? ''; if ($action === 'list') { $resp = runUapi("Ftp list_ftp"); $listFtp = $resp['result']['data'] ?? []; $flash = "List FTP di-refresh."; } elseif ($action === 'add') { $user_raw = trim($_POST['user'] ?? ''); $pass_raw = $_POST['pass'] ?? ''; $quota = intval($_POST['quota'] ?? 500); $homedir_raw = trim($_POST['homedir'] ?? 'public_html'); if ($user_raw === '' || $pass_raw === '') { $flash = "Username dan password wajib diisi."; } else { $user_q = shell_quote_single($user_raw); $pass_q = shell_quote_single($pass_raw); $homedir_q = shell_quote_single($homedir_raw); $uapiCmd = "Ftp add_ftp user=$user_q pass=$pass_q quota=$quota homedir=$homedir_q"; $resp = runUapi($uapiCmd); $ip = getServerIP(); $last_summary = [ 'action' => 'add', 'username' => $user_raw, 'password' => $pass_raw, 'ip' => $ip, 'api' => $resp, ]; // refresh list $listFtp = runUapi("Ftp list_ftp")['result']['data'] ?? []; $flash = "Permintaan tambah akun diproses. Lihat hasil di bawah."; } } elseif ($action === 'delete') { $user_raw = trim($_POST['user'] ?? ''); if ($user_raw === '') { $flash = "User tidak boleh kosong."; } else { $user_q = shell_quote_single($user_raw); $resp = runUapi("Ftp delete_ftp user=$user_q"); $last_summary = [ 'action' => 'delete', 'username' => $user_raw, 'api' => $resp, ]; $listFtp = runUapi("Ftp list_ftp")['result']['data'] ?? []; $flash = "Permintaan hapus diproses."; } } elseif ($action === 'edit') { $user_raw = trim($_POST['user'] ?? ''); $new_pass_raw = $_POST['new_pass'] ?? ''; if ($user_raw === '' || $new_pass_raw === '') { $flash = "User dan password baru wajib diisi."; } else { $user_q = shell_quote_single($user_raw); $pass_q = shell_quote_single($new_pass_raw); // Use whmapi1 passwdftp to change ftp password // Note: whmapi1 runs as root — it must be available and your PHP process must be allowed to call it $whmResp = runWhmapi1("passwdftp user=$user_q password=$pass_q"); $ip = getServerIP(); $last_summary = [ 'action' => 'edit', 'username' => $user_raw, 'password' => $new_pass_raw, 'ip' => $ip, 'api' => $whmResp, ]; $listFtp = runUapi("Ftp list_ftp")['result']['data'] ?? []; $flash = "Permintaan update password diproses."; } } elseif ($action === 'info') { $info = runUapi("Variables get_user_information"); $flash = "Informasi user/server diambil."; } } else { // default page load: load list $resp = runUapi("Ftp list_ftp"); $listFtp = $resp['result']['data'] ?? []; } // ----------------- HTML / UI ----------------- ?> FTP Manager - cPanel (Stable)

cPanel FTP Manager — Stable

Add / Delete / Edit-password (whmapi1) — Menampilkan result summary

Daftar Akun FTP

Klik Refresh untuk mengambil daftar terbaru
UsernameHome DirUsageQuotaAksi
Belum ada akun FTP atau tekan Refresh.
— Ringkasan
Username
Password
IP Server
Full API result (click)
Proteksi file ini — script menampilkan password plain text. Hapus setelah selesai atau tambahkan proteksi.