Search K
Appearance
Appearance
FileManager allows performing basic filesystem operations from DirectAdmin control panel.
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 using the FileManager.
Create the /usr/local/directadmin/scripts/custom/file_manager_remove_pre.sh script with code:
#!/bin/bash
if [[ "${file#${home}}" == /domains/*/public_html ]]; then
echo "You cannot delete your public_html link!"
exit 1
fiAnd make it executable:
chmod 700 /usr/local/directadmin/scripts/custom/file_manager_remove_pre.shYou can add more paths not permitted for deletion by adding another if statement after the check for public_html.
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 ctpto the /etc/mime.types file.
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.shIf 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.
# ls -la /etc/mime.types
-rw-r--r--. 1 root root 53011 Dec 4 2018 /etc/mime.types# grep zip /etc/mime.types
application/x-bzip2 bz2
application/x-gzip gz tgz
application/zip zip# /usr/local/directadmin/directadmin config | grep mime
apachemimetypes=/etc/mime.typesIf you make changes to the directadmin.conf to adjust the apachemimetypes value, be sure to restart directadmin after making the change.
When requesting a file, e.g.,
/CMD_FILE_MANAGER/file.txtYou can now add GET options, either:
fm_head=10or:
fm_tail=10to view the starting or ending number of lines for that file, e.g.,
/CMD_FILE_MANAGER/file.txt?fm_tail=5Only 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.