|
From: Ben B. <bat...@gm...> - 2012-03-23 01:08:58
|
Hi everyone Does anyone know of a way to setup a sort of "trash" directory for ProFTPD? It would be great to setup a trash directory for when remote users delete a file/directory over FTP. If they delete something in error, it is recoverable on the server by an admin with shell access. Is there a module out there that can do something like this? I thought of using mod_exec and the ExecBeforeCommand directive to intercept the DELE command and run a shell script which moves the files to a "trash" directory. With mod_exec it would probably have to be a file copy rather than move to a trash directory. mod_exec seems to require that the FTP DELE command would still have to run after the ExecBeforeCommand command has been run. A file move can be substantially faster than copying files to a new location then deleting the originals, especially for large files or a large number of small files. A way of returning true/false from the ExecBeforeCommand command/script to ProFTPD would be great to "trick" the FTP server and client into thinking that the DELE command has been run successfully, even though behind the scenes it was my file move shell script doing the business. Has anyone ever managed to setup something like this? Is there a way that this could be done? I've had a brief look at the developer's guide and had a dig around in some of the modules, mod_exec / mod_readme to get an idea of how modules are structured. Learning a proper language like C is something I've been meaning to do for some time so writing my own mod_trash module could be a good project. I'm a proficient PHP developer and the syntax of C doesn't look too foreign. I would envisage needing 4 config directives: - module on|off... so you can have different configs in <Directory or <IfUser blocks etc. - location of desired trash directory - preserve paths true|false... so if you delete the file: dir1/dir2/dir3/foo.bar then the structure dir1/dir2/dir3/ is first created in trash directory, then foo.bar is moved there. Or foo.bar is just moved straight to your trash directory without the full paths being preserved. - touch files/directories true|false... whether to change the access time attribute of files/directories when sent to trash. Similar to the way Samba's recycle VFS module works. So you can then have a script in cron to delete files/directories last accessed >x days ago One problem that springs to mind is that the process of the DELE command for a directory in FTP seems to be to run a recursive file list under that directory and gradually issue a DELE command for each file. So if "preserve paths" is enabled, for each file DELE I need to check if the path exists and if not create it, before I move the file to trash. Another is how to deal with collisions. So you try to delete a file but it already exists in the trash folder you need to maybe trash it with a new name with a timestamp or an incremental number added to the end. Anyway... does anyone know of anything out there that can do that for ProFTPD? How daunting would it be to kick off my first project in C by writing a module like this? Or would most people try and accomplish something like this more on the OS or FS level, rather than within a daemon? Cheers, Ben |