#! /usr/bin/perl -w # - authentication module for pure-ftpd using vpasswd vpopmail password files. # - Saturday, 12 May 2002 - released # - copyright (c) Dan Caescu - daniel@guitar.ro , jamie_fd@yahoo.com # - vpopmail has to be compiled with clear text passwords in order for # - this to work. # - also, there would be great if you would run pure-ftpd with chroot flags # - 17 Nov 2002, added e-mail checking, a hint from Frank Jedi @ pureftpd # - I guess it works..? :) # - greets to Rox (Roxana Raluca) . # modified by Filip Rembialkowski # changes include: # mysql support (for quota, throttling etc), # default domain, # other customizations and fixup # Needs understanding! Read the whole script before using! # Change the following settings according to your needs use strict; my $VPOPMAIL_PATH = '/home/vpopmail'; my $UID = 1010; my $GID = 100; my $DEFAULT_DOMAIN = 'fake.domain'; my $mysql_binary = '/usr/bin/mysql'; my $mysql_user = 'public'; my $mysql_pass = 'public'; my $mysql_db = 'mydb'; # Don't change anything below that line haha my $AUTHD_ACCOUNT = $ENV{AUTHD_ACCOUNT} or die; my $AUTHD_PASSWORD = $ENV{AUTHD_PASSWORD} or die; # Checking if AUTHD_ACCOUNT is like user[@domain] $AUTHD_ACCOUNT =~ /^[^@]+(\@([a-z0-9-]+\.)+[a-z]+)?$/i or die; # We take care of the user/domain pair 'cause the user comes # in the user@domain style my @user_domain = split('@', $AUTHD_ACCOUNT); # push def. domain in unless user specified it $user_domain[1] = $DEFAULT_DOMAIN unless defined($user_domain[1]); $AUTHD_ACCOUNT = join('@',@user_domain); open (VPASSWD, "$VPOPMAIL_PATH/domains/" . $user_domain[1] . '/vpasswd') or die; # We take care of the user/pass from vpasswd my($auth_ok,$servname,$quota,$dl,$ul) = (0,'test',0,0,0); while () { chomp; my @date_useri = split ':'; if ($user_domain[0] eq $date_useri[0]) { if ( $AUTHD_PASSWORD eq $date_useri[7]) { $auth_ok = 1; } else { $auth_ok = -1; } last; } } close VPASSWD; if ($auth_ok == 1) { my $QUERY = "SELECT `ServerName`, `QuotaMB`, `ULKBps`, `DLKBps` FROM `vserver` WHERE `active`='Yes' AND `account`='$AUTHD_ACCOUNT'"; my @res = `echo "$QUERY" | $mysql_binary -u$mysql_user -p$mysql_pass $mysql_db -Ns -B`; if (@res != 1) { $auth_ok = 0; } else { for(@res){ chomp; ($servname,$quota,$ul,$dl) = split /\t/; $quota = int($quota * 1024 * 1024); $ul = int($ul * 1024); $dl = int($dl * 1024); last; } } } print "auth_ok:$auth_ok\n", "uid:$UID\n", "gid:$GID\n", "dir:/home/www/$servname\n", "throttling_bandwidth_ul:$ul\n", "throttling_bandwidth_dl:$dl\n", "user_quota_size:$quota\n", "end\n";