File Manager Hooks

filemanager_pre.sh

This hook script is to be called before DA runs anything from CMD_FILE_MANAGER or CMD_API_FILE_MANAGER.

Saves needing to use all_pre.sh for File Manager-related blocks.

Environment variables

All GET/POST variables are passed via the environment.

  • path : directory where the action is happening
  • api (0|1): whether or not the action originated from the api (CMD_API_FILE_MANAGER)
  • fileX : file name of uploaded file... variable generated for every uploaded file.

file_manager_upload_pre.sh

Custom hook script which is run for each fully uploaded file in File Manager.

The hook acts on the temporary file right before it is moved to the target destination.

If hook exits with non-zero status, file upload is cancelled and temporary file is removed by DirectAdmin (destination is left untouched).

Note: The hook must be accessible to the user as it is executed as the user. Recommended permissions for the hook are 0755.

Environment variables

  • file: absolute path for uploaded temporary file
  • username: uploader username
  • home: home directory of user

ClamAV example

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

#!/bin/sh
clamdscan --no-summary --fdpass "$file"

Note: on systems where clamav daemon is running TCP-only, use --stream instead of --fdpass.

# Ensure it is accessible by the user
chmod 0755 /usr/local/directadmin/scripts/custom/file_manager_upload_pre.sh

file_manager_upload_post.sh

DEPRECATED: DirectAdmin 1.677 introduces a successor hook file_manager_upload_pre.sh instead.

Custom hook script to run after a User has finished uploading a file in the CMD_FILE_MANAGER or CMD_API_FILE_MANAGER.

This would be useful if you'd like to run ClamAV on a given file after the upload.

Note that DA doesn't take any special actions on the files based on the output, other than throwing an error in the resulting upload message.

If you exit with a non-zero result, be sure to echo some text to clarify what the problem is.

E.g., if there was a virus (as decided by ClamAV), you might want to delete the uploaded file in your script, echo a notice about that, and exit 1;.

Environment variables

  • file: location of uploaded file
  • username: uploader username
  • home: home directory of user
Last Updated: