This module has an embedded Perl interpreter, and offers several facilities based on Perl language.
The main feature is to add a protocol for hooks, it means that instead of giving the path to an executable (or script) in a cscript directive or in a custom site command, you can use a Perl script with direct access to server internals
Perl is provided as a module, keeping main server from adding many useless dependancies.
Warning and errors are logged in the file "perlerr.log", located in the directory specified in the logdir directive of the config file.
Just add the line
module = /path/to/libwzd_perl.soin your config file.
You must ensure that the perl shared library (for ex libperl.so, or perl58.dll) is accessible (in the PATH or in the same directory), or module loading will fail.
wzd::ftp2sys "path"
Converts the path for the current user (relative to the ftp homedir) to an absolute filename (for the system).
$realpath = wzd::ftp2sys "/upload";
Note that the returned path can be different for different users, if they have different home directories.
wzd::logperl "message"
Put the message in perl log file.
wzd::logperl "zipscript: file is corrupted";
wzd::putlog level, "message"
Put the message in log file, only if level is greater or equal to the current loglevel. level is an integer in range 0 to 10, 0 is the lowest level (reserved to debug) and 10 is reserved to critical error messages. default level is 5
wzd::putlog 5, "zipscript: file is corrupted";
wzd::send_message message
Use the string given in argument to send reply to client.
You should send one line at a time.
wzd::send_message_raw message
Sends the string given in argument to client, without any processing. It must be a valid FTP reply.
This function must be use with care.
Example:
wzd::send_message_raw "200-test line\r\n";
If reply is complete, script must set variable wzd_reply to "1" to indicate that reply has been completed.
wzd::vars "get"/"set", variable_name [, value]
This function gives access to server internal variables. Use the 'get' method to read variables, the 'set' method to change variables (you need to provide a new value).
See Config variables
vars_group "get"/"set", groupname, variable_name [, value]
This function gives access to group variables. Use the 'get' method to read variables, the 'set' method to change variables (you need to provide a new value).
See Group variables
wzd::vars_group "new", groupname
Use this function to create a new group.
wzd::vars_user "get"/"set", username, variable_name [, value]
This function gives access to user variables. Use the 'get' method to read variables, the 'set' method to change variables (you need to provide a new value).
Note that this concern variables for user definition, and not for connected users: for example, you can't get the current ip (this has a sense only for connected users).
See User variables
wzd::vars_user "new", username, password, group
Use this function to create a new user.
wzd::vfs "mkdir"/"rmdir", dirname
Create or remove a directory. Directory name must be an absolute path !.
wzd::vfs "read", filename/dirname
Get infos on file or directory. Returned string has format:
"user/group/mode"User and group are names (or "unknown"), and mode is the octal number corresponding to file permissions.
wzd::vfs "link", "create", dirname, linkname
Create a symbolic link linkname to the existing directory dirname. Both paths are relative to user homedir (so, "." is the user current directory, and / is the homedir of the current user).
wzd::vfs "link", "create", "-f", dirname, linkname
This function is identical to the precedent, except that dirname is given for filesystem (so it must be an absolute path).
wzd::vfs "link", "create", "-f", "c:\real", "lnk"
wzd::vfs "link", "remove", linkname
Remove a symbolic link (path is relative to user homedir).
wzd::args
Use this variable contains the arguments for the current command.
The following example will teach you how to create a perl script that is called after each file upload, and checks if zip files are valid by calling an external application (not provided here).
##for wzdftpd community ##simple .zip checker ## ## ##Put in wzd.cfg under 'cscript' ##cscript = POSTUPLOAD perl:c:/wzdftpd/scripts/zip_check.pl %username %usergroup {%filepath} ## ## ##set path to unzip.exe my %binary; $binary{UNZIP} = "./scripts/unzip.exe"; ## ## ##main proc sub zip_check { my ($user,$group,$file) = split " ", $wzd_args, 3; if ($file =~ m/.*\.zip/i) { my @args = ($binary{UNZIP}, "-qqt", "$file"); my $rc = system( @args ); if ($rc == 0) { wzd::send_message "+----------------------------------------------------"; wzd::send_message "$user\($group\) uploaded GOOD zip file '$file'."; wzd::send_message "+----------------------------------------------------"; } else { rename "$file", "$file.bad"; wzd::send_message "+----------------------------------------------------"; wzd::send_message "$user\($group\) uploaded BAD zip file '$file'."; wzd::send_message "+----------------------------------------------------"; } } } zip_check;