#============================================================================# # vHost - one-step solution for all virtual hosting needs # # V15proftpd - proftpd virtualization module # # # # Copyright(c) Chaogic Systems, LLC. http://chaogic.com # # Author: Jake Fan # # # # This is Free Software; permission to use, copy, modify, and distribute # # this software and its documentation for any purpose - with or without fee # # - is hereby granted, provided that the above copyright information and # # this permission notice appear in all copies and documentations. This # # software is provided "as is" without express or implied warranty. For # # more details, see GNU General Public License as published by the Free # # Software Foundation. # # # #============================================================================# $X eq "configuration" && do { ################################################ ### EDITABLE CONFIGURATIONS ################################################## ### ftp directory name on virtual hosts. home directory for anonymous ftp. # will be created under "var/". # $ftpDir = "ftp"; $ftpDir = "ftp"; ### the user which proftpd runs as. when left blank, it will be retrieved # from $proftpdCf. # $ftpUser = ""; $ftpUser = ""; ### proftpd configuration file. # $proftpdCf = "/etc/proftpd.conf"; $proftpdCf = "/etc/proftpd.conf"; ### proftpd reload command sequence. separate multiple commands with shell # meta characters such as "|", ";", "||", "&&", etc. leave blank if invoked # by inetd. # $proftpdRc = "/etc/rc.d/init.d/proftpd reread"; $proftpdRc = "/etc/rc.d/init.d/proftpd reread"; ### $proftpdCf virtual host configuration. vhost will replace "[HOST_NAME]", # "[OWNER_NAME]", and "[IP_ADDRESS]" with actual values. variables found # in "./V00hostconf" will also be expanded. # $proftpdC = <<"---eoc---eoc---eoc---"; $proftpdC = <<"---eoc---eoc---eoc---"; ServerName [HOST_NAME] ServerAdmin $ADMIN@[HOST_NAME] DefaultRoot ~ vuser TransferLog $VHOME/[HOST_NAME]/var/log/xferlog # uncomment the line below for ip-based virtual hosts. # AuthUserFile /etc/vdata/passwd.[HOST_NAME] RequireValidShell on AllowOverwrite on User ftp Group ftp UserAlias anonymous ftp ---eoc---eoc---eoc--- ### DO NOT TOUCH ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING!! ### SanityChecking ########################################################### /^\s*User[\s"']+([^\s"']+)/i && ($ftpUser ||= $1) for !$ftpUser && Cat $proftpdCf; $ERR = 1, Error "$MOD: \$ftpDir = '$ftpDir'" if !CheckN $ftpDir; $ERR = 1, Error "$MOD: \$ftpUser = '$ftpUser'" if !getpwnam $ftpUser; $ERR = 1, Error "$MOD: \$proftpdCf = '$proftpdCf'" if !-f $proftpdCf; $ERR = 1, Error "$MOD: \$proftpdRc = '$proftpdRc'" if $proftpdRc && ($proftpdRc !~ /^\// || !-x (split /[\s|&;]+/, $proftpdRc)[0]); }; $X eq "initialization" && do { ############################################### if ($ONCFG) { `chown 0:$GHID $proftpdCf $NERR` if !-o $proftpdCf; `chmod 0600 $proftpdCf $NERR` if ((stat $proftpdCf)[2] & 07777) != 0600; #GroupAdd $ftpUser; GroupAdd "ftp"; Flock $proftpdCf, "+<", 0 if !grep /^\s*$FOOT/, Cat $proftpdCf; BackupCf $proftpdCf; s/^(\s*DefaultServer\s)/#$1/i for @FILE; print FILE @FILE; print FILE "\n$FOOT\n"; print FILE "DefaultAddress 127.0.0.1\n"; print FILE "DefaultServer on\n"; print FILE "DefaultRoot ~ vuser\n"; Flock 0; } Error5 "'$U' is a system user" if $ARGV[0] eq "deluser" && $U eq $ftpDir && $VPWD{$U}; }; $X eq "addhost" && do { ###################################################### `touch $VHOME/$H/var/log/xferlog $NERR`; `mkdir $VHOME/$H/var/$ftpDir $NERR`; `mkdir $VHOME/$H/var/$ftpDir/pub $NERR`; `cp -Rp $VHOME/$H/home/$ftpDir/. $VHOME/$H/var/$ftpDir $NERR`; `rm -r $VHOME/$H/home/$ftpDir $NERR`; `ln -s ../var/$ftpDir $VHOME/$H/home/$ftpDir $NERR`; AddConf $proftpdCf, $proftpdC # if grep (/^\s*# \Q$H\E $SIGN/, Cat $proftpdCf) || !grep (/^\s*]/i, Cat $proftpdCf) && $I ne $HIP; ; ReloadRc 0; }; $X eq "delhost" && do { ###################################################### DelConf $proftpdCf, $proftpdC if $_d; ReloadRc 0 if $_d; }; $X eq "reload" && do { ####################################################### ReloadRc 0 if $_f && $USER eq "root"; ReloadRc $proftpdRc; }; $X eq "finalization" && do { ################################################# if ($ARGV[0] eq "addhost" || $ARGV[0] eq "adduser" && $U eq $ftpDir) { `chown -h $O[2]:$GUID $VHOME/$H/home/$ftpDir $NERR`; } ReloadRc $proftpdRc if !$_q && $ARGV[0] =~ /^(addhost|delhost)$/; }; 1;