<?php
/**
* class TA_Vpopmail
*
* Gives Access to Vpopmail functionallity
* Vpopmail Version 5.3.8
* I don't know what other versions this class will work with
* Please email me with luck with other versions or changes made
* to work with other versions
*
* Vpopmail bin files must be copied into a directory accessible by
* your web server and chown vpopmailuser.webservergroup and chmod 6755
* I suggest that they be put in a directory by themselves
* I make no warranty as to the security of this setup
* Examples: chown vpopmail.nobody *
* chmod 6755 *
* vadddomain and vdeldomain must be suid root
* Example: chown root.nobody vadddomain
* chmod 6755 vadddomain
*
* @author Rick Robinson <hide@address.com>
* @link http://www.terraaccess.com Terra Access
* @package rTA_Admin
* @version 0.1
* @copyright Copyright 2003-2005 Terra Access
*
* @link http://www.inter7.com Inter7
* @access public
*/
//Class defined constants
define ( "VPOP_VERSION", "5.3.8");
//set this to the path of your vpopmail binaries
define ( "VPOP_BIN_PATH", "") ;
define ( "VPOP_CANNOT_DELETE_POSTMASTER", -99 );
define ( "VPOP_PASSWORD_REQUIRED", -100 );
//vpopmail defined constants
define ( "VA_SUCCESS", 0 );
define ( "VA_ILLEGAL_USERNAME", -1 );
define ( "VA_USERNAME_EXISTS", -2 );
define ( "VA_BAD_DIR", -3 );
define ( "VA_BAD_U_DIR", -4 );
define ( "VA_BAD_D_DIR", -5 );
define ( "VA_BAD_V_DIR", -6 );
define ( "VA_EXIST_U_DIR", -7 );
define ( "VA_BAD_U_DIR2", -8 );
define ( "VA_SUBDIR_CREATION", -9 );
define ( "VA_USER_DOES_NOT_EXIST", -10 );
define ( "VA_DOMAIN_DOES_NOT_EXIST", -11 );
define ( "VA_INVALID_DOMAIN_NAME", -12 );
define ( "VA_DOMAIN_ALREADY_EXISTS", -13 );
define ( "VA_COULD_NOT_MAKE_DOMAIN_DIR", -14 );
define ( "VA_COULD_NOT_OPEN_QMAIL_DEFAULT", -15 );
define ( "VA_CAN_NOT_MAKE_DOMAINS_DIR", -16 );
define ( "VA_COULD_NOT_UPDATE_FILE", -17 );
define ( "VA_CRYPT_FAILED", -18 );
define ( "VA_COULD_NOT_OPEN_DOT_QMAIL", -19 );
define ( "VA_BAD_CHAR", -20 );
define ( "VA_SQWEBMAIL_PASS_FAIL", -21 );
define ( "VA_BAD_UID", -22 );
define ( "VA_NO_AUTH_CONNECTION", -23 );
define ( "VA_MEMORY_ALLOC_ERR", -24 );
define ( "VA_USER_NAME_TOO_LONG", -25 );
define ( "VA_DOMAIN_NAME_TOO_LONG", -26 );
define ( "VA_PASSWD_TOO_LONG", -27 );
define ( "VA_GECOS_TOO_LONG", -28 );
define ( "VA_QUOTA_TOO_LONG", -29 );
define ( "VA_DIR_TOO_LONG", -30 );
define ( "VA_CLEAR_PASSWD_TOO_LONG", -31 );
define ( "VA_ALIAS_LINE_TOO_LONG", -32 );
define ( "VA_NULL_POINTER", -33 );
define ( "VA_INVALID_EMAIL_CHAR", -34 );
class TA_Vpopmail {
/**
* TA_Vpopmail::$vpopmail_return
*
* Holds the unparsed string returned by vpopmail functions
*
* @access public
*/
var $vpopmail_return;
/**
* TA_Vpopmail::$vpopmail_parsed_return
*
* Holds the parsed values in an array of values
* Return is parsed by "\n" the newline charactor
* which is currently used by vpopmail
*
* @access public
*/
var $vpopmail_parsed_return = array();
/**
* TA_Vpopmail::add_domain()
*
* Adds a Virtual Server of the specified Domain ($domain)
*
* VPOPMAIL USAGE
*
* vadddomain: usage: vadddomain [options] virtual_domain [postmaster password]
* options: -v prints the version
* -q quota_in_bytes (sets the quota for postmaster account)
* -b (bounces all mail that doesn't match a user, default)
* -e email_address (forwards all non matching user to this address)
* -u user (sets the uid/gid based on a user in /etc/passwd)
* -d dir (sets the dir to use for this domain)
* -i uid (sets the uid to use for this domain)
* -g gid (sets the gid to use for this domain)
* -O optimize adding, for bulk adds set this for all
* except the last one
* -r generate a random password for postmaster
*
* @param string $domain
* @param string $postmaster_password
* @param string $options Valid Command Line String
* @return integer 0 for success
* @access public
*/
function add_domain ( $domain, $postmaster_password, $options="" )
{
//capture any output from system call
ob_start();
$command_line = $options ." " .$domain ." " .$postmaster_password ;
system(VPOP_BIN_PATH .'/vadddomain '.$command_line ,$ret);
//call failed
if ( $ret != 0 )
{
//get the captured contents and store in $vpopmail_return
$this->vpopmail_return = ob_get_contents();
//put captured return in $vpopmail_parsed_return array
$this->parse_return ();
}
//silently clear buffer so output is not displayed
ob_end_clean();
return $ret ;
}
/**
* TA_Vpopmail::delete_domain()
*
* Removes Virtual Domain and all accounts associated with
* the domain
*
* VPOPMAIL USAGE
* vdeldomain: usage: [options] domain_name
* options: -v (print version number)
*
* @param string $domain Domain to Remove
* @return integer 0 for success
* @access public
*/
function delete_domain ( $domain )
{
//capture any output from system call
ob_start();
system(VPOP_BIN_PATH .'/vdeldomain '.$domain ,$ret);
//call failed
if ( $ret != 0 )
{
//get the captured contents and store in $vpopmail_return
$this->vpopmail_return = ob_get_contents();
//put captured return in $vpopmail_parsed_return array
$this->parse_return ();
}
//silently clear buffer so output is not displayed
ob_end_clean();
return $ret ;
}
/**
* TA_Vpopmail::add_user()
*
* Adds an email address
*
* VPOPMAIL USAGE
* vadduser: usage: [options] email_address [passwd]
* options: -v (print the version)
* -q quota_in_bytes (sets the users quota)
* -s (don't rebuild the vpasswd.cdb file, faster for large sites)
* -c comment (sets the gecos comment field)
* -e standard_encrypted_password
* -n no_password
* -r generate a random password
*
* @param string $email_address
* @param string $password Must include password or use the -n or -f options
* @param string $options Must be a valid options string
* @return integer 0 for success
* @access public
*/
function add_user ( $email_address, $password, $options="" )
{
//capture any output from system call
ob_start();
$command_line = $options ." " .$email_address ." " .$password ;
system ( VPOP_BIN_PATH .'/vadduser '.$command_line, $ret ) ;
//call failed
if ( $ret != 0 )
{
//get the captured contents and store in $vpopmail_return
$this->vpopmail_return = ob_get_contents();
//put captured return in $vpopmail_parsed_return array
$this->parse_return ();
}
//silently clear buffer so output is not displayed
ob_end_clean();
return $ret ;
}
/**
* TA_Vpopmail::delete_user()
*
* Deletes User Specified by $email_address
* Cannot delete postmaster account
*
* VPOPMAIL USAGE
* vdeluser: usage: [options] email_address
* options: -v (print version number)
*
* @param string $email_address Full Email Address with Domain
* @return integer 0 for success
* @access public
*/
function delete_user ( $email_address )
{
list ( $user, $domain ) = split ( "@", $email_address, 2 ) ;
//Cannot delete postmaster account
if ( $user == "postmaster" )
{
$this->vpopmail_return = "Cannot Delete Postmaster Account" ;
return VPOP_CANNOT_DELETE_POSTMASTER ;
}
//capture any output from system call
ob_start();
system(VPOP_BIN_PATH .'/vdeluser '.$email_address,$ret);
//call failed
if ( $ret != 0 )
{
//get the captured contents and store in $vpopmail_return
$this->vpopmail_return = ob_get_contents();
//put captured return in $vpopmail_parsed_return array
$this->parse_return ();
}
//silently clear buffer so output is not displayed
ob_end_clean();
return $ret ;
}
/**
* TA_Vpopmail::change_password()
*
* Changes a users password
*
* VPOPMAIL USAGE
*
* vpasswd: usage: [options] email_address [password]
* options: -v (print version number)
* Note: password is required for this function
*
* @param string $email_address
* @param string $new_password
* @return integer 0 for success
* @access public
*/
function change_password ( $email_address , $new_password )
{
if ( $new_password == "" )
{
return VPOP_PASSWORD_REQUIRED;
}
//capture any output from system call
ob_start();
$command_line = $email_address ." " .$new_password;
system(VPOP_BIN_PATH .'/vpasswd '.$command_line ,$ret);
//call failed
if ( $ret != 0 )
{
//get the captured contents and store in $vpopmail_return
$this->vpopmail_return = ob_get_contents();
//put captured return in $vpopmail_parsed_return array
$this->parse_return ();
}
//silently clear buffer so output is not displayed
ob_end_clean();
return $ret ;
}
/**
* TA_Vpopmail::user_info()
*
* Gets user information, parses into lines and stores in
* $vpopmail_return and $vpopmail_parsed_return
*
* VPOPMAIL USAGE
* vuserinfo: usage: [options] email_address
* options: -v (print version number)
* -a (display all fields, this is the default)
* -p (display crypted password)
* -u (display uid field)
* -g (display gid field)
* -c (display comment field)
* -d (display directory)
* -q (display quota field)
* -Q (display quota usage)
* -C (display clear text password)
* -l (display last authentication time)
*
* @param string $email_address
* @param string $options
* @return integer 0 for success
* @access public
*/
function user_info ( $email_address, $options="" )
{
//capture any output from system call
ob_start();
$command_line = $options ." " .$email_address;
system(VPOP_BIN_PATH .'/vuserinfo '.$command_line ,$ret);
//get the captured contents and store in $vpopmail_return
$this->vpopmail_return = ob_get_contents();
//put captured return in $vpopmail_parsed_return array
$this->parse_return ();
//silently clear buffer so output is not displayed
ob_end_clean();
return $ret ;
}
/**
* TA_Vpopmail::get_password()
*
* Uses vuserinfo to retrieve user password
*
* VPOPMAIL USAGE
* user_info ( -C $email_address )
*
* @param string $email_address
* @return integer 0 for success
* @access public
*/
function get_password ( $email_address )
{
//capture any output from system call
ob_start();
$command_line = "-C " .$email_address;
system(VPOP_BIN_PATH .'/vuserinfo '.$command_line ,$ret);
//get the captured contents and store in $vpopmail_return
$this->vpopmail_return = ob_get_contents();
//put captured return in $vpopmail_parsed_return array
$this->parse_return ();
//silently clear buffer so output is not displayed
ob_end_clean();
return $ret ;
}
/**
* TA_Vpopmail::pop_bull()
*
* Posts a message to Virtual Domain Users
* Can be used to get a list of email addresses
* contained in virtual domain -n -V options
*
* VPOPMAIL USAGE
* usage: vpopbull [options] [virtual_domain] [...]
* -v (print version number)
* -V (verbose)
* -f email_file (file with message contents)
* -e exclude_email_addr_file (list of addresses to exclude)
* -n (don't mail. Use with -V to list accounts)
* -c (default, copy file)
* -h (use hard links)
* -s (use symbolic links)
*
* @param string $domain
* @param string $options
* @return integer 0 for success
* @see get_email_addresses()
* @access public
*/
function pop_bull ( $domain, $options="" )
{
//capture any output from system call
ob_start();
$command_line = $options ." " .$domain;
system(VPOP_BIN_PATH .'/vpopbull ' .$command_line ,$ret);
//get the captured contents and store in $vpopmail_return
$this->vpopmail_return = ob_get_contents();
//put captured return in $vpopmail_parsed_return array
$this->parse_return ();
//silently clear buffer so output is not displayed
ob_end_clean();
return $ret ;
}
/**
* TA_Vpopmail::get_email_addresses()
*
* Uses vpopbull to get a list of email addresses
* and parses them into $vpopmail_parsed_return
* Leave $domain blank to get a complete list
* including all domains
*
* VPOPMAIL USAGE
* usage: vpopbull -n -V $domain
*
* @param string $domain
* @return integer 0 for success
* @see pop_bull()
* @see $vpopmail_parsed_return
* @access public
*/
function get_email_addresses ( $domain )
{
//capture any output from system call
ob_start();
$command_line = "-n -V " .$domain;
system(VPOP_BIN_PATH .'/vpopbull ' .$command_line ,$ret);
//get the captured contents and store in $vpopmail_return
$this->vpopmail_return = ob_get_contents();
//put captured return in $vpopmail_parsed_return array
$this->parse_return ();
//silently clear buffer so output is not displayed
ob_end_clean();
return $ret ;
}
/**
* TA_Vpopmail::set_user_quota()
*
* Sets a users quota if $email_address is a full email address
* or sets quota for all addresses if $email_address is just the
* domain name. Pass 'NOQUOTA' in $quota to remove quota restrictions
*
* VPOPMAIL USAGE
*
* vsetuserquota: [options] email_address quota_in_bytes
* options: -v (print version number)
*
* @param string $email_address Full Email Address or just Domain
* @param string $quota In bytes or 'NOQUOTA'
* @param string $options
* @access public
*/
function set_user_quota ( $email_address, $quota, $options="" )
{
//NOQUOTA in $quota to remove quota for user or domain
/* vsetuserquota: [options] email_address quota_in_bytes
options: -v (print version number) */
//capture any output from system call
ob_start();
$command_line = $options ." " .$email_address ." " .$quota;
system(VPOP_BIN_PATH .'/vsetuserquota '.$command_line ,$ret);
//call failed
if ( $ret != 0 )
{
//get the captured contents and store in $vpopmail_return
$this->vpopmail_return = ob_get_contents();
//put captured return in $vpopmail_parsed_return array
$this->parse_return ();
}
//silently clear buffer so output is not displayed
ob_end_clean();
return $ret ;
}
/**
* TA_Vpopmail::parse_return()
*
* Parse values in $vpopmail_return and store in $vpopmail_parsed_return array
* return number of parsed values. Currently uses line break
*
*/
function parse_return ()
{
$this->vpopmail_parsed_return = split ("\n", $this->vpopmail_return );
return count ( $this->vpopmail_parsed_return );
}
}
?>