Complete Guide to Customizing the DirectAdmin FileManager: Protecting Files

This article provides a comprehensive guide to customizing and extending the behavior of the DirectAdmin FileManager. It covers preventing deletion of critical paths, adding custom file extensions to the EDIT button, modifying permissions of uploaded files, troubleshooting file download issues related to MIME types, and using head/tail parameters to preview parts of a file directly from the FileManager.

Customizing the DirectAdmin FileManagerProtecting Files

~2 min read · Updated Mar 1, 2026

1. Preventing Deletion of Specific Files or Directories


Users sometimes delete important directories such as public_html. To prevent this, DirectAdmin allows you to intercept deletion attempts using the file_manager_remove_pre.sh hook.

Create the script:

/usr/local/directadmin/scripts/custom/file_manager_remove_pre.sh

Content:


#!/bin/bash
if [[ "${file#${home}}" == /domains/*/public_html ]]; then
    echo "You cannot delete your public_html link!"
    exit 1
fi

Make it executable:

chmod 700 /usr/local/directadmin/scripts/custom/file_manager_remove_pre.sh

You can block additional paths by adding more if conditions.


---

2. Adding Custom File Types to the EDIT Button


For a file to be editable in FileManager, its extension must be recognized as a text-based MIME type in /etc/mime.types.

Example: enabling the CakePHP .ctp extension:


text/x-php     ctp

Any MIME type starting with text/ will be treated as editable.


---

3. Changing Permissions for Uploaded Files


You can automatically adjust permissions for files uploaded via FileManager using all_post.sh.

Create:

/usr/local/directadmin/scripts/custom/all_post.sh

Content:


#!/bin/sh

CHMODVAL=700
ULPATH=/home/${username}${path}

setfile() {
  if [ "$1" = "" ]; then
    return;
  fi

  F=`echo $1 | cut -d/ -f4 | awk '{ print substr($1,1,length($1)-6) }'`

  chmod ${CHMODVAL} ${ULPATH}${F}
}

if [ "$command" = "/CMD_FILE_MANAGER/" ] || [ "$command" = "/CMD_FILE_MANAGER" ]; then
  if [ "$action" = "upload" ]; then
    setfile $file1
    setfile $file2
    setfile $file3
    setfile $file4
    setfile $file5
    setfile $file6
    setfile $file7
    setfile $file8
  fi
fi

exit 0;

Make executable:

chmod 755 /usr/local/directadmin/scripts/custom/all_post.sh

---

4. Fixing File Download Issues (Files Displaying as Plain Text)


If downloaded files appear as raw text instead of triggering a download, the issue is usually related to missing or incorrect MIME types.

Checklist:

  • Ensure /etc/mime.types exists and is readable:
ls -la /etc/mime.types
-rw-r--r-- 1 root root ...
  • Verify required MIME types exist:

grep zip /etc/mime.types
application/zip zip
  • Ensure DirectAdmin is using the correct MIME Error! Hyperlink reference not valid.

/usr/local/directadmin/directadmin config | grep mime
apachemimetypes=/etc/mime.types

If you modify directadmin.conf, restart DirectAdmin afterward.


---

5. Using Head and Tail Commands in FileManager


You can preview the beginning or end of a file directly from FileManager using GET parameters.

View the first 10 lines:

/CMD_FILE_MANAGER/file.txt?fm_head=10

View the last 5 lines:

/CMD_FILE_MANAGER/file.txt?fm_tail=5

Only one parameter can be used at a time. Output is always displayed as text/plain.


Written & researched by Dr. Shahin Siami

Related Articles

Email Client Configuration & Dovecot Quota/Monitoring Guide for DirectAdmin Users

This guide explains how to configure popular email clients (iPhone Mail, Thunderbird, Gmail POP/SMTP), enable Dovecot LMTP quota warnings, and check the last login time for all email accounts on a DirectAdmin server. It includes step by step instructions, recommended IMAP/SMTP settings, and useful administrative scripts.

Continue

Troubleshooting Dovecot in DirectAdmin – Fixing IMAP Errors, Authentication Issues, and SSL Certificate Checks

Dovecot is the IMAP/POP3 server used by DirectAdmin. Sometimes users encounter errors such as “Connection dropped by IMAP server” or “unknown user” during authentication. This guide explains how to fix corrupted Dovecot indexes, understand authentication logs, hide unnecessary warnings, and manually inspect SSL certificates on IMAP ports 143 and 993.

Continue

DNS Troubleshooting in DirectAdmin – When named is Running but Domains Do Not Resolve

Sometimes the named (BIND) service runs normally, yet DNS queries fail or domains do not resolve from outside. This guide provides a complete troubleshooting workflow for checking named listeners, firewall rules, named.conf configuration, DNS propagation issues, subdomain problems, resolv.conf errors, and common Apache/Nginx misconfigurations.

Continue

Managing DNS Records in DirectAdmin – Complete Practical Guide for Administrators

DirectAdmin provides a powerful DNS management system that allows administrators to control TTL values, create SRV records, enable DNSSEC, manage subdomain delegation, automate TLSA records, and perform mass DNS updates. This guide explains all essential DNS operations in DirectAdmin with real-world examples and best practices.

Continue

DNS and Nameservers in DirectAdmin – Complete, Practical, and Professional Guide

DNS is the backbone of the internet, responsible for translating domain names into IP addresses. DirectAdmin allows you to create private nameservers (ns1/ns2), manage DNS zones, configure DNS clustering, use external DNS, and troubleshoot common issues. This guide provides a complete, clear, and practical explanation of DNS concepts and their implementation in DirectAdmin.

Continue

CustomBuild in DirectAdmin – Complete Guide to Installation, Updates, Configuration, and Advanced Customization

CustomBuild is DirectAdmin’s primary software management system. It installs, updates, configures, and rebuilds essential services such as Apache, Nginx, PHP, MariaDB/MySQL, Exim, Dovecot, FTP servers, and more. Because most components are compiled from source, CustomBuild offers exceptional flexibility, fast access to new versions, and optimized performance.

Continue