|
1 | 1 | <?php |
2 | 2 |
|
3 | 3 | /** |
4 | | - * The Kinsmen File Manager v2.0 |
| 4 | + * The Kinsmen File Manager v2.0.1 |
5 | 5 | * |
6 | 6 | * A comprehensive, modern file manager with cPanel styling and all essential features: |
7 | 7 | * - File Tree Navigation |
|
19 | 19 | * - Sorting and filtering |
20 | 20 | */ |
21 | 21 |
|
| 22 | +// CWP Usage |
| 23 | +$cwp = false; |
| 24 | + |
22 | 25 | // 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 | + } |
24 | 44 |
|
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 | +} |
27 | 81 |
|
28 | 82 | // Configuration |
29 | 83 | $config = [ |
@@ -520,42 +574,7 @@ function compressItems($items, $destination, $type = "zip") |
520 | 574 | } |
521 | 575 | function isEditable($file) |
522 | 576 | { |
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; |
559 | 578 | } |
560 | 579 |
|
561 | 580 | // Function to move item to trash |
@@ -2554,12 +2573,34 @@ function showFiles(files) { |
2554 | 2573 |
|
2555 | 2574 | // Check if a file is editable |
2556 | 2575 | 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 | + ]; |
2559 | 2590 |
|
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); |
2561 | 2601 | } |
2562 | 2602 |
|
| 2603 | + |
2563 | 2604 | // Show context menu |
2564 | 2605 | function showContextMenu(x, y, type) { |
2565 | 2606 | const contextMenu = document.getElementById('context-menu'); |
|
0 commit comments