Filemanager

FileManager allows performing basic filesystem operations from DirectAdmin control panel.

How to prevent deleting certain files

Since Users often delete things they shouldn't, it may be wise to limit their ability to delete certain things. In this example, we'll block them from deleting their /public_html symbolic link using the FileManager.

Create the /usr/local/directadmin/scripts/custom/filemanager_pre.sh script with code:

#!/bin/sh
if [ "${button}" = "delete" ]; then
    if env|grep -m1 -q "=/public_html$$"; then
        echo "You cannot delete your public_html link!"
        exit 1
    fi
fi
exit 0

And make it executable:

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

You can add more paths not permitted for deletion by adding another if statement after the check for public_html.

How to add own files to EDIT button

If you've got a custom file type which you'd like to be editable in the FileManager, it must be considered a text file by the system. The way DA checks for this is with the mime types file /etc/mime.types. The format of this file is the type of the file, and the extension(s) on the right, separated by one or more tabs.

In order for your extension to be considered a text file, it must be present in the /etc/mime.types file, and also have the type starting with text/.

Just as an example, the CakePHP extension is ctp, so you'd add something like this:

text/x-php     ctp

to the /etc/mime.types file.

How to change permissions for uploaded files

To alter a file uploaded through the FileManager, create the /usr/local/directadmin/scripts/custom/all_post.sh script with 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}
}

TMP=/tmp/txt.txt
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;

And make it executable:

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

File download does not work

If you're using the FileManager and files downloaded in the FileManager are being displayed as plaintext/raw instead of their true form (displaying an image, downloading/saving a zip file, etc.,) then it would imply that the mime types for those files are not being added to the headers along with the file.

The file that DirectAdmin uses to include these types is the /etc/mime.types file. If this file is missing, not world readable, incomplete, or DirectAdmin isn't using it, this could explain the behavior.

  1. Make sure it exists, and check the permissions:
# ls -la /etc/mime.types
-rw-r--r--. 1 root root 53011 Dec  4  2018 /etc/mime.types
  1. Check its contents for the zip/gz types to see if they're present, e.g.,
# grep zip /etc/mime.types
application/x-bzip2             bz2
application/x-gzip              gz tgz
application/zip                 zip
  1. Lastly, check the directadmin config to ensure that the correct path is still being used:
# /usr/local/directadmin/directadmin config | grep mime
apachemimetypes=/etc/mime.types

If you make changes to the directadmin.conf to adjust the apachemimetypes value, be sure to restart directadmin after making the change.

Using head and tail commands in FileManager

When requesting a file, e.g.,

/CMD_FILE_MANAGER/file.txt

You can now add GET options, either:

fm_head=10

or:

fm_tail=10

to view the starting or ending number of lines for that file, e.g.,

/CMD_FILE_MANAGER/file.txt?fm_tail=5

Only one (either head or tail) can be used at a time. 10 can be replaced with any positive integer. The Content-Type header will always be set to text/plain.

Last Updated: