5.3. Perl module

5.3.1. Description

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 dependencies.

Warning and errors are logged in the file "perlerr.log", located in the directory specified in the logdir directive of the config file.

5.3.2. Installation

Just add the line

/path/to/libwzd_perl.so = allow
in your config file, in the modules section.

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.

5.3.3. Available PERL commands and variables

5.3.4. A complete example

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;