Skip to content

Commit 6cba5ab

Browse files
authored
Update filemanager.php
Updated editable files function
1 parent a3d1dfc commit 6cba5ab

File tree

1 file changed

+84
-43
lines changed

1 file changed

+84
-43
lines changed

filemanager.php

Lines changed: 84 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* The Kinsmen File Manager v2.0
4+
* The Kinsmen File Manager v2.0.1
55
*
66
* A comprehensive, modern file manager with cPanel styling and all essential features:
77
* - File Tree Navigation
@@ -19,11 +19,65 @@
1919
* - Sorting and filtering
2020
*/
2121

22+
// CWP Usage
23+
$cwp = false;
24+
2225
// Set timezone
23-
date_default_timezone_set("UTC");
26+
date_default_timezone_set("Africa/Lagos");
27+
28+
if ($cwp) {
29+
$path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
30+
$segments = explode("/", trim($path, "/"));
31+
32+
$url_token = null;
33+
$url_username = null;
34+
35+
foreach ($segments as $index => $segment) {
36+
if ($segment === "filemanager.php" && $index > 0) {
37+
$url_username = $segments[$index - 1];
38+
if ($index > 1) {
39+
$url_token = $segments[$index - 2];
40+
}
41+
break;
42+
}
43+
}
2444

25-
$username = ""; // Username for directory listing
26-
$root_path = ""; // Path to the root directory
45+
if (!$url_username || !$url_token) {
46+
header("HTTP/1.1 403 Forbidden");
47+
echo "Access denied. Invalid URL format.";
48+
exit();
49+
}
50+
51+
$token_dir = "/home/$url_username/.tokens/";
52+
$token_file = $token_dir . $url_token;
53+
54+
if (!file_exists($token_file)) {
55+
header("HTTP/1.1 403 Forbidden");
56+
echo "Access denied. Invalid token.";
57+
exit();
58+
}
59+
60+
$token_data = json_decode(file_get_contents($token_file), true);
61+
62+
if (time() > $token_data["expiry"]) {
63+
unlink($token_file);
64+
header("HTTP/1.1 403 Forbidden");
65+
echo "Access denied. Token expired.";
66+
exit();
67+
}
68+
69+
if ($token_data["username"] !== $url_username) {
70+
header("HTTP/1.1 403 Forbidden");
71+
echo "Access denied. Username mismatch.";
72+
exit();
73+
}
74+
75+
$username = $token_data["username"];
76+
$root_path = "/home/$username";
77+
} else {
78+
$username = "joe";
79+
$root_path = "/var/www/html/001_public";
80+
}
2781

2882
// Configuration
2983
$config = [
@@ -520,42 +574,7 @@ function compressItems($items, $destination, $type = "zip")
520574
}
521575
function isEditable($file)
522576
{
523-
$editableExtensions = [
524-
"txt",
525-
"html",
526-
"htm",
527-
"css",
528-
"js",
529-
"php",
530-
"xml",
531-
"json",
532-
"md",
533-
"log",
534-
"config",
535-
"ini",
536-
"yml",
537-
"yaml",
538-
"sql",
539-
"sh",
540-
"Dockerfile",
541-
".gitignore",
542-
".gitkeep",
543-
".htaccess",
544-
".htpasswd",
545-
".htaccess.dist",
546-
".env",
547-
".env.example",
548-
".env.local",
549-
".env.test",
550-
".env.development",
551-
".env.staging",
552-
".env",
553-
".ini",
554-
".conf",
555-
];
556-
$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
557-
558-
return in_array($extension, $editableExtensions);
577+
return true;
559578
}
560579

561580
// Function to move item to trash
@@ -2554,12 +2573,34 @@ function showFiles(files) {
25542573

25552574
// Check if a file is editable
25562575
function isEditable(fileName) {
2557-
const editableExtensions = ['txt', 'html', 'htm', 'css', 'js', 'php', 'xml', 'json', 'md', 'log', 'config', 'ini', 'yml', 'yaml', 'sql', 'sh'];
2558-
const extension = fileName.split('.').pop().toLowerCase();
2576+
const editableExtensions = [
2577+
'txt', 'text', 'log', 'md', 'markdown', 'nfo', 'rtf',
2578+
'html', 'htm', 'css', 'scss', 'sass', 'less', 'js', 'jsx', 'ts', 'tsx', 'vue', 'svelte',
2579+
'php', 'phtml', 'php3', 'php4', 'php5', 'phps',
2580+
'py', 'rb', 'pl', 'cgi', 'sh', 'bash', 'zsh', 'ps1', 'bat', 'cmd', 'rake',
2581+
'env', 'ini', 'conf', 'config', 'cfg', 'yaml', 'yml', 'toml', 'rc', 'properties', 'prefs',
2582+
'json', 'xml', 'csv', 'tsv', 'xhtml',
2583+
'sql', 'sqlite', 'db', 'dump',
2584+
'htaccess', 'htpasswd', 'user.ini',
2585+
'blade.php', 'twig', 'tpl', 'smarty', 'ejs', 'hbs', 'mustache', 'liquid', 'njk',
2586+
'makefile', 'mk', 'gradle', 'pom', 'build', 'dockerfile', 'docker-compose',
2587+
'gitignore', 'gitattributes', 'editorconfig', 'eslintignore', 'npmrc',
2588+
'bashrc', 'zshrc', 'bash_profile', 'profile', 'aliases'
2589+
];
25592590

2560-
return editableExtensions.includes(extension);
2591+
const editableFilenames = [
2592+
'.env', '.htaccess', '.htpasswd', '.gitignore', '.gitattributes',
2593+
'.bashrc', '.zshrc', '.bash_profile', '.editorconfig', '.npmrc',
2594+
'Dockerfile', 'Makefile', 'Procfile', 'Vagrantfile', 'README', 'LICENSE'
2595+
];
2596+
2597+
const lower = fileName.toLowerCase();
2598+
const ext = lower.includes('.') ? lower.split('.').pop() : '';
2599+
2600+
return editableExtensions.includes(ext) || editableFilenames.includes(fileName);
25612601
}
25622602

2603+
25632604
// Show context menu
25642605
function showContextMenu(x, y, type) {
25652606
const contextMenu = document.getElementById('context-menu');

0 commit comments

Comments
 (0)