Iavor Raytchev wrote:

It seems now the next bottleneck is 'how will php talk to the daemon'.


My PHP interface to the daemon would work like this:


example.php ------------------------------------------------------------------------------ <?

include( "vpopmail.pobj" );


# Information for login $Domain = 'system.admins'; $User = 'rwidmer'; $Pass = 'mypassword';

$vpop = new vpopmail( $Domain, $User, $Pass );


# Information to create accounts $Domain = 'developersdesk.com'; $User = 'rwidmer'; $Pass = 'mypassword';

$AliasName = ' minimaillist';

$AliasContents = array(
   '[EMAIL PROTECTED]',
   '[EMAIL PROTECTED]',
   '[EMAIL PROTECTED]',
   '[EMAIL PROTECTED]',
   '[EMAIL PROTECTED]',
   );


# Do it...


$vpop->domainAdd( $Domain, $Pass );

$vpop->userAdd( $Domain, $User, $Pass );

$vpop->aliasAdd( $Domain, $AliasName, $AliasContents );

$DomainUsers = $vpop->userList( $Domain );

#  DomainUsers is an array containing:
#   'minimaillist' => 'alias',
#   'postmaster' => 'user',
#   'rick' => 'user',

$AliasList - $vpop->aliasList( $Domain, $AliasName );


# AliasList is an array containing: # '[EMAIL PROTECTED]', # '[EMAIL PROTECTED]', # '[EMAIL PROTECTED]', # '[EMAIL PROTECTED]', # '[EMAIL PROTECTED]', # # Note they are in alpha order now.

$vpop->domainList( 'inter7.com' );
#  This is an invalid domain error

$vpop->userList( 'inter7.com', 'kbo' );
#  This is an invalid domain error

$vpop->userList( 'developersdesk.com', 'kbo' );
#  This is an invalid user error

$vpop->close();

?>
------------------------------------------------------------------------------



All of which should result in the same data stream as the 'telnet' session I posted earlier. We need to add some kind of error handling, probably return false, and set an error variable in the object which you query with vpop->error().


Off the top of my head it might look like this... (never even attempted to compile with PHP, so expect syntax errors... )




vpopmail.pobj
------------------------------------------------------------------------------

class Vpopmail {

var $socket;
var $error;


####################################################### # # c o n s t r u c t o r #

function Vpopmail( $Domain, $User, $Password ) {

/* Set the port for our service */
$service_port = '1234';

/* Get the IP address for the target host. */
$address = gethostbyname('localhost');

/* Create a TCP/IP socket. */
$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($this->socket < 0) {
   $this->error =  "socket_create() failed: reason: " .
                   socket_strerror($socket) . "\n";
   return;
}


#echo "Attempting to connect to '$address' on port '$service_port'...";


$result = socket_connect($this->socket, $address, $service_port);
if ($result < 0) {
   $this->error =
   "socket_connect() failed.\nReason: ($result) " .
        socket_strerror($result) . "\n";
   return;

#  Send the username
$in  = "user [EMAIL PROTECTED]";
socket_write($this->socket, $in, strlen($in));

$out = socket_read($this->socket, 2048)) {
if( 'ok' != $out ) {
   $this->error = "Login failed - $Out\n";
   socket_close( $this->socket );
   unset( $this->socket );
   return;
}


# Send the password $in = "pass $Password\n"; socket_write($socket, $in, strlen($in));

$out = socket_read($socket, 2048)) {
if( 'ok' != $out ) {
   $this->error = "Login failed - $Out\n";
   socket_close( $this->socket );
   unset( $this->socket );
   return;

}


####################################################### # # f u n c t i o n c l o s e #

function close() {

echo "Closing socket...";
socket_close($this->socket);
}


####################################################### # # f u n c t i o n domainAdd #

function domainAdd( $Domain, $Password ) {

#  Build the request
$in  = "adddomain $Domain $Password\n";

#  Send the request
socket_write($this->socket, $in, strlen($in));

$out = socket_read($this->socket, 2048)) {
if( 'ok' != $out ) {
   $this->error = $Out;
   return false
   }

else {
   $this->Error = '';
   return true;
   }
}


####################################################### # # f u n c t i o n userAdd #

function userAdd( $Domain, $User, $Password ) {

#  Build the request
$in  = "adduser $Domain $User $Password\n";

#  Send the request
socket_write($this->socket, $in, strlen($in));

$out = socket_read($this->socket, 2048)) {
if( 'ok' != $out ) {
   $this->error = $Out;
   return false
   }

else {
   $this->Error = '';
   return true;
   }
}



#######################################################
#
#  f u n c t i o n      aliasAdd
#

function aliasAdd( $Domain, $AliasName, $AliasList ) {

#  Build the request
$in  = "addalias $Domain $User $Password\n";

#  Send the request
socket_write($this->socket, $in, strlen($in));

$out = socket_read($this->socket, 2048)) {

if( 'enter alias addr?' == $out ) {
   while( list( , $Alias ) = each( $AliasList )) {
      $in = "$Alias\n";
      socket_write($this->socket, $in, strlen($in));
      $out = socket_read($this->socket, 2048));
      if( 'enter alias addr?' != $out ) break;
   }
}

$in = "\n";

if( 'enter alias addr? == $out ) {
   socket_write($this->socket, $in, strlen($in));
   $out = socket_read($this->socket, 2048));
   }


if( 'ok' == $out ) { $this->Error = ''; return true; }

else {
   $this->error = $Out;
   return false
   }
}



#######################################################
#
#  f u n c t i o n      userList
#

function userList( $Domain ) {

#  Build the request
$in  = "list $Domain\n";

#  Send the request
socket_write($this->socket, $in, strlen($in));

$out = socket_read($this->socket, 2048)) {

if( 'ok' == $out ) {
   return array();
   }

elseif( 'err - ' == substr( $out, 0, 6 )) {
   $this->error = $Out;
   return false
   }

else {
   $out = socket_read($this->socket, 2048)) {

   while( list( , $Alias ) = each( $AliasList )) {
      $List[] = $out;
      $out = socket_read($this->socket, 2048)) {
      }
   }


if( 'ok' == $out ) { $this->Error = ''; return $List; }

else {
   $this->error = $Out;
   return false
   }
}


} # End of object vpop


?>
------------------------------------------------------------------------------

Other functions to write...



vpopmail_domain_del
vpopmail_domain_alias_add
vpopmail_domain_ex_add
vpopmail_domain_ex_del
vpopmail_alias_domain_ex_add


IP Map


$string = vpopmail_ip_map_get( $IP );

vpopmail_ip_map_add( $IP, $Domain );

vpopmail_ip_map_del( $IP, $Domain );

$array = vpopmail_ip_map_show();


Limits


$array = vpopmail_limits_get( $Domain );

vpopmail_limits_set( $Domain, $Limits );

vpopmail_limits_del( $Domain );


User Management


vpopmail_user_del( $Domain, $User );

vpopmail_user_quota_set( $Domain, $User, $Quota );

User Authentication
$array = vpopmail_auth_user( $Domain, User, Password );

$array = vpopmail_auth_getall( $Domain );

$array = vpopmail_auth_getpw( $Domain, $User );

$array = vpopmail_passwd( $Domain, $User, $Password );

Last Authentication Tracking
vpopmail_lastauth_get( $Domain, $User );

vpopmail_lastauth_set( $Domain, $User, $RemoteIP? );

vpopmail_lastauthip_get( $Domain, $User );

Alii
vpopmail_alias_add( $Domain, $User, $Alias );

vpopmail_alias_del( $Domain, $User );

vpopmail_alias_remove( $Domain, $User, $Alias );

$array = vpopmail_alias_get( $Domain, $User );

$array = vpopmail_alias_get_names( $Domain );
vpopmail_alias_get_all


Error Handling vpopmail_error()


NOTE:


Parameter lists for functions are mostly the same as vpopmail, but on the PHP side I have always put them in order from least to most specific, for example

function( $Domain, $User, $Password )

where the vpopmail parameters might be

function( user, domain, password )






Reply via email to