Table of Contents

Custom event scripts

Custom PHP scripts can be automatically executed when the users perform one of the many monitored actions.

For example, to automatically run custom PHP code after a file is uploaded, you can simply place a PHP file named “upload.php” inside the folder “customizables/events/”.

Here's an example script:

Set file permissions after upload:

<?php
chmod($data['full_path'], 0644);

Scan a file with ClamAV:

<?php
 
if ($data['filesize'] > 0) {
	$pathToClamAV = 'clamscan';
	$command = \FileRun\Utils\CLI::escapeshellcmd($pathToClamAV)." ".escapeshellarg($data['full_path']);
	$return_text = [];
	$return_code = 0;
	exec($command, $return_text, $return_code);
 
	$return_text = implode("\n", $return_text);
 
	if (!str_contains($return_text, 'Scanned files: 1')) {
		jsonOutput([
			'success' => false,
			'skip' => true,
			'msg' => 'No files were scanned'
		]);
	} else if (!str_contains($return_text, 'Infected files: 0')) {
		jsonOutput([
			'success' => false,
			'skip' => true,
			'msg' => 'Viruses were found inside this file'
		]);
	}
}

In the above, you might want to make sure ClamAV daemon is running and use “clamdscan” instead, to speed this process up. You might also want to add command line options for handling the file (move or remove it).

Debug $data for the available information.

Event names

The following can be used to find out what filename should you use for the event PHP script.

//more used
	'upload' => 'File uploaded',
	'receive_upload' => 'File received (via upload)',
	'receive_copy' => 'File received (via copy)',
	'receive_move' => 'File received (via move)',
	'folder_receive_copy' => 'Folder received (via copy)',
	'folder_receive_move' => 'Folder received (via move)',
	'download' => 'File downloaded',
	'provide_download' => 'File downloaded by another user',
	'preview' => 'File previewed',
	'weblink_access' => 'WebLink folder access',
	'weblink_download' => 'WebLink download',
	'weblink_upload' => 'File received (via WebLink)',
	'shared_folder_available' => 'New shared folder available',
	'shared_file_available' => 'New shared file available',
	'comment_added' => 'File comment added',
	'comment_received' => 'File comment received',
	'metadata_changed' => 'Metadata changed',
	'login' => 'Login',
	'folder_shared' => 'Folder shared',
	'file_shared' => 'File shared',
	'weblink_create' => 'WebLink created',
	'file_encrypted' => 'File encrypted',
	'file_decrypted' => 'File decrypted',
	'label_set' => 'Label changed',
	'label_received' => 'Label received',
	'star_set' => 'Star added',
	'star_removed' => 'Star removed',
 
	'collection_created' => 'Collection created',
	'collection_add_item' => 'Item added to collection',
	'collection_removed' => 'Collection removed',
	'collection_item_removed' => 'Item removed from collection',
	'collection_renamed' => 'Collection renamed',
 
//less used
	'weblink_update' => 'WebLink modified',
	'weblink_remove' => 'WebLink removed',
	'logout' => 'Logout',
	'login_failed' => 'Login failed',
	'login_failed_account_deactivated' => 'Account deactivated',
	'password_changed' => 'Password changed',
	'user_manually_activated' => 'User manual activation',
	'user_manually_deactivated' => 'User manual deactivation',
	'comment_removed' => 'File comment removed',
	'folder_unshared' => 'Folder unshared',
	'file_unshared' => 'File unshared',
//successful file actions
	'file_moved' => 'File moved',
	'file_copied' => 'File copied',
	'file_deleted' => 'File deleted',
	'deleted_file_restored' => 'Restored deleted file',
	'trash_delete_file' => 'File permanently deleted',
	'file_renamed' => 'File renamed',
	'zip_files'	=> 'Files zipped',
	'file_sent_by_email' => 'File sent by email',
	'file_locked' => 'File locked',
	'file_unlocked' => 'File unlocked',
	'version_restored' => 'File version restored',
	'version_deleted' => 'File version deleted',
	'archive_extracted' => 'Archive extracted',
//successful folder actions
	'new_folder' => 'New folder created',
	'folder_moved' => 'Folder moved',
	'folder_deleted' => 'Folder deleted',
	'deleted_folder_restored' => 'Restored deleted folder',
	'trash_delete_folder' => 'Folder permanently deleted',
	'folder_renamed' => 'Folder renamed',
	'folder_copied' => 'Folder copied',
	'trash_empty' => 'Trash emptied',
	'trash_empty_fail' => 'Failed to empty trash',
//failed file actions
	'upload_failed' => 'Upload failed',
	'download_failed' => 'Download failed',
	'weblink_upload_failed' => 'WebLink upload failed',
	'file_copy_failed' => 'Failed to copy file',
	'file_deletion_failed' => 'Failed to delete file',
	'file_move_failed' => 'Failed to move file',
	'failed_file_rename' => 'Failed to rename file',
	'zip_files_failed' => 'Failed to zip files',
	'file_lock_failed' => 'Failed to lock file',
	'file_unlock_failed' => 'Failed to unlock file',
	'failed_to_add_comment' => 'Failed to add comment to file',
	'failed_to_remove_comment' => 'Failed to remove comment from file',
	'version_restoration_failed' => 'Failed to restore file version',
	'version_deletion_failed' => 'Failed to delete file version',
//failed folder actions
	'new_folder_failed' => 'Failed to create new folder',
	'failed_folder_rename' => 'Failed to rename folder',
	'folder_copy_failed' => 'Failed to copy folder',
	'folder_deletion_failed' => 'Failed to delete folder',
	'folder_move_failed' => 'Failed to move folder',
//failed collection action
	'collection_create_failed' => 'Failed to create collection',
	'collection_add_item_failed' => 'Failed to add item to collection',
	'collection_removal_failed' => 'Collection removal failed',
	'collection_item_removal_failed' => 'Failed to remove collection item',
	'collection_rename_failed' => 'Failed to rename collection',
//misc
	'folder_notification_settings_changed' => 'Folder notification settings changed',
	'new_user_registration' => 'New user registration',
	'password_recovery' => 'Password recovery',
//administrative
	'user_added' => 'User added',
	'guest_user_added' => 'Guest user added',
	'user_edited' => 'User edited',
	'user_deleted' => 'User deleted',
	'role_added' => 'Role added',
	'role_edited' => 'Role edited',
	'role_deleted' => 'Role deleted',
	'space_quota_warning' => 'Space quota warning',
	'user_added_to_group' => 'User added to group',
	'user_removed_from_group' => 'User removed from group'

Execute code before the action happens

To automatically run custom PHP code before a file is downloaded, you can simply place a PHP file named “file.download.php” inside the folder “customizables/events/”.

To prevent the download action with an custom error message, here is a sample code:

<?php
// Your business logic goes here
// Return an Array like the following for preventing the action from continuing
return [
	'error' => [
		'private' => 'The user is not allowed', //used for logging
		'public' => 'You are not allowed to download this file' //shown to user
	]
];

Here is a complete list of hook names:

folder.read
folder.download
folder.create
folder.copy
folder.move
folder.rename
folder.delete
folder.metadata.read
folder.metadata.write
folder.comments.read
folder.comments.write
folder.star
folder.notifications.change
folder.share
folder.weblink.info
folder.weblink
file.weblink
folder.zip

file.read
file.download
file.preview
file.write
file.write.string
file.write.upload
file.write.move
file.write.copy
file.move
file.rename
file.copy
file.delete
file.extract
file.metadata.read
file.metadata.write
file.comments.read
file.comments.write
file.star
file.notifications.change
file.share
file.weblink.info
file.zip

collection.add.folder
collection.add.collection
collection.add.file
collection.remove.item
collection.create
collection.remove
collection.rename
collection.item.read
collection.read
collection.weblink.info
collection.weblink