phpgroupware-developers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-developers] Full VMailMgr support for phpGW


From: Dan Kuykendall (Seek3r)
Subject: [Phpgroupware-developers] Full VMailMgr support for phpGW
Date: Wed, 01 May 2002 10:37:20 -0700

Havent had much time to do anything more with this yet, but wanted to
get it out to you.
For now I have been putting the settings in the header.inc.php

$GLOBALS['phpgw_info']['server']['vmailmgr_domain'] = 'domain1.com';
$GLOBALS['phpgw_info']['server']['vmailmgr_domainpass'] = 'somepass';

Anyways, heres the diff and the vmailmgr class file for 0.9.12.
I am going to work on this stuff some more and see how to add it as an
app that simply has a collection of hooks, or merge it into the code as
clean as possible.

This little bit of code allows for very powerful integration with
vmailmgr+qmail.
Basicly when the account is created, deleted, has a password change, the
action is also delt with on the mail server, keeping everything in
perfect sync.

The options must be added to the header.inc.php, auth needs to be mail
and accounts needs to be sql. As I said this will all be improved as I
go.

Seek3r

Alejandro Borges wrote:
> 
> > I have it working for 0.9.12 perfectly well. There are a handful of
> > files that I have patches for. I will put together the patch for you
> > later today.
> >
> :) Great!
> > This only works for a single domain tho. The problem is that when I do
> > account add/edit/delete I need to have that domains name and password. I
> > also have no way to decide which domain I should be creating the account
> > for.,Now it CAN be done. It just need an extra layer added on top and
> > you will be able to see where teh patches are and build from there. You
> > can just create the username as  address@hidden
> > Then make an array of the domains and there password.
> Perfectly understood
> >
> > $vmailmgr_domains['domain1.com'] = 'somepassword';
> > $vmailmgr_domains['domain2.com'] = 'someotherpassword';
> > 
> > So at the point where you call the account creation function you can get
> > the passowrd by parsing the username and take the sendon part (the part
> > after the @ sign)
> > $domainpassword = $vmailmgr_domains[$username_part2];
> Great, perfectly explained!
> >
> > >From there you have what you need.
> Indeed..... thx so much seek3r, ill try and port it to 0.9.14 (which is
> what ive got already running) as is, and to see where does it adapt best
> to my situation. Im also thinking about making a qmailadmin-like tool
> for phpgw to be used in this kind of thing (i need stuff that others
> -non unix- can manage). Maybe youll also find it cool.
> 
> Also, about the rebuilt of the e-mail app. If you need someone to test
> it, help out, develop, whatever....id be also interested in that. I
> agree that it could be better.
> 
> Thanx a lot.... i appreciate it very much
> 
> Alex
Index: phpgwapi/inc/class.accounts_sql.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/class.accounts_sql.inc.php,v
retrieving revision 1.46.2.4
diff -r1.46.2.4 class.accounts_sql.inc.php
80a81,83
>                       $account_lid = $this->id2name($account_id);
>                       $GLOBALS['phpgw']->vmailmgr = 
> CreateObject('phpgwapi.vmailmgr');
>                       $returnvals = 
> $GLOBALS['phpgw']->vmailmgr->vdeluser($account_lid);
268,272c271,277
<             $this->db->query("insert into phpgw_accounts (account_lid, 
account_type, account_pwd, "
<               . "account_firstname, account_lastname, account_status, 
account_expires) values ('" . $account_info['account_lid']
<               . "','" . $account_info['account_type'] . "','" . 
md5($account_info['account_passwd']) . "', '" . 
$account_info['account_firstname']
<               . "','" . $account_info['account_lastname'] . "','" . 
$account_info['account_status'] . "','" . $account_info['account_expires']
<               . "')",__LINE__,__FILE__);
---
>           $this->db->query("insert into phpgw_accounts (account_lid, 
> account_type, account_pwd, "
>               . "account_firstname, account_lastname, account_status, 
> account_expires) values ('" . $account_info['account_lid']
>               . "','" . $account_info['account_type'] . "','" . 
> md5($account_info['account_passwd']) . "', '" . 
> $account_info['account_firstname']
>               . "','" . $account_info['account_lastname'] . "','" . 
> $account_info['account_status'] . "','" . $account_info['account_expires']
>               . "')",__LINE__,__FILE__);
>                       $GLOBALS['phpgw']->vmailmgr = 
> CreateObject('phpgwapi.vmailmgr');
>                       $returnvals = 
> $GLOBALS['phpgw']->vmailmgr->vadduser($account_info['account_lid'], 
> $account_info['account_passwd']);
Index: phpgwapi/inc/class.auth_mail.inc.php
===================================================================
RCS file: /cvsroot/phpgroupware/phpgwapi/inc/class.auth_mail.inc.php,v
retrieving revision 1.7
diff -r1.7 class.auth_mail.inc.php
66c66,67
<               function change_password($old_passwd, $new_passwd) {
---
>               function change_password($old_passwd, $new_passwd, $account_id 
> = '')
>               {
68c69,84
<                       return False;
---
>                       if (! $account_id)
>                       {
>                               $account_id = 
> $GLOBALS['phpgw_info']['user']['account_id'];
>                       }
>                       $account_lid = 
> $GLOBALS['phpgw']->accounts->id2name($account_id);
> 
>                       if($phpgw_info['server']['mail_login_type'] == 
> 'vmailmgr')
>                       {
>                               $GLOBALS['phpgw']->vmailmgr = 
> CreateObject('phpgwapi.vmailmgr');
>                               $returnvals = 
> $GLOBALS['phpgw']->vmailmgr->vchpass($account_lid, $new_passwd);
>                               //echo 'returnvals 
> <pre>';print_r($returnvals);echo'</pre>';
>                       }
>                       else
>                       {
>                               return False;
>                       }
Index: preferences/changepassword.php
===================================================================
RCS file: /cvsroot/phpgroupware/preferences/changepassword.php,v
retrieving revision 1.30
diff -r1.30 changepassword.php
40c40,42
<               $phpgw->template->set_var('sql_message',lang('note: This 
feature does *not* change your email password. This will '
---
>               if ($phpgw_info['server']['auth_type'] != 'vmailmgr' &&  
> $phpgw_info['server']['mail_login_type'] != 'vmailmgr')
>               {
>                       $phpgw->template->set_var('sql_message',lang('note: 
> This feature does *not* change your email password. This will '
41a44
>               }
<?php
  /**************************************************************************\
  * phpGroupWare API - Auth from Mail server                                 *
  * This file written by Dan Kuykendall <address@hidden>            *
  * Authentication based on mail server                                      *
  * Copyright (C) 2000, 2001 Mike Bell <address@hidden>                   *
  * -------------------------------------------------------------------------*
  * This library is part of the phpGroupWare API                             *
  * http://www.phpgroupware.org/api                                          * 
  * ------------------------------------------------------------------------ *
  * This library is free software; you can redistribute it and/or modify it  *
  * under the terms of the GNU Lesser General Public License as published by *
  * the Free Software Foundation; either version 2.1 of the License,         *
  * or any later version.                                                    *
  * This library is distributed in the hope that it will be useful, but      *
  * WITHOUT ANY WARRANTY; without even the implied warranty of               *
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
  * See the GNU Lesser General Public License for more details.              *
  * You should have received a copy of the GNU Lesser General Public License *
  * along with this library; if not, write to the Free Software Foundation,  *
  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA            *
  \**************************************************************************/

  /* $Id: class.auth_mail.inc.php,v 1.10 2001/09/25 14:52:10 milosch Exp $ */

        class vmailmgr
        {
                var $domain;
                var $domainpass;
                var $vm_tcphost;
                var $vm_tcphost_port;

                function vmailmgr()
                {
                        $this->domain = 
$GLOBALS['phpgw_info']['server']['vmailmgr_domain'];
                        $this->domainpass = 
$GLOBALS['phpgw_info']['server']['vmailmgr_domainpass'];
                        $this->vm_tcphost = 
$GLOBALS['phpgw_info']['server']['vmailmgr_tcphost'];
                        $this->vm_tcphost_port = 
$GLOBALS['phpgw_info']['server']['vmailmgr_tcphost_port'];
                }

                function vm_daemon_raw($arg)
                {
                        // om/23feb01 - dual vmailmgrd support : unix & tcp 
socket

                        if ($this->vm_tcphost)
                        {
                                // TCP SOCKET - default port = 322.
                                if (!$this->vm_tcphost_port)
                                {
                                        $this->vm_tcphost_port = "322";
                                }
        $vmailsock = fsockopen ($vm_tcphost, $this->vm_tcphost_port, $errno, 
$errstr, 10);
        if (!$vmailsock)
                                {
                                        die("Failed to open tcp socket, is 
daemon running on host '".$this->vm_tcphost.":".$this->vm_tcphost_port."'? 
<br>\nError: $errno - $errstr");
                                }
                        }
                        else
                        {
                                // UNIX SOCKET
              $vmailfile = "/tmp/.vmailmgrd";
                                if (file_exists("/etc/vmailmgr/socket-file"))
                                {
                                        $socketfile = (file 
("/etc/vmailmgr/socket-file"));
                                }
                                $socketfile = trim($socketfile[0]);
                                if ($socketfile != "")
                                {
                                        $vmailfile = $socketfile;
                                }
                                $vmailsock = fsockopen ($vmailfile, 0, $errno, 
$errstr, 4);
                                if (!$vmailsock)
                                {
                                        die("Failed to open unix socket file at 
'$vmailfile', is daemon running? <br>\n Error: $errno - $errstr");
                                }
                        }

                        /* Parse $arg, which should be an array of arguments to 
pass to the
      daemon, into a glob consisting of each argument proceeded by a
      two-byte representation of its length. */
                        for ($x=0; $x < sizeof($arg); $x++)
                        {
                                $commandlength = strlen($arg[$x]);
                                $high=(($commandlength & (0xFF << 8)) >> 8);
                                $low=($commandlength & 0xFF);
                                $command .= sprintf("%c%c%s", $high, $low, 
$arg[$x]);
                        }


                        /* Create the header, which consists of another two 
byte length
      representation, the number of arguments being passed, and the
      command string created above. */

      $args=$x-1;
      $commandlength=strlen($command);
      $high=(($commandlength & (255 << 8)) >> 8);
      $low=($commandlength & 255);
      $commandstr = sprintf("\002%c%c%c", $high, $low+1, $args).$command;

                        /* Pass it all to the daemon */
      fputs($vmailsock, $commandstr);
                        /* Get the response */

                        $value = ord( fgetc ($vmailsock));
                        $length = (ord(fgetc($vmailsock)) << 8) + 
ord(fgetc($vmailsock));

                        if ($length == 0)
                        {
                                while (!feof($vmailsock))
                                {
                                        $out.=fread($vmailsock, 65535);
                                }
                                fclose($vmailsock);
                                return $out;
                        }

                        $message = fread ($vmailsock, $length);

                        /*      Close the socket        */
                        fclose($vmailsock);

                        return array($value, $message);
                }

                /* vadduser, takes domain name, domainpass, username, 
userpassword, and an
        array of forwarding desinations, returns an array consisting of an
        integer exit code and message. */

                function vadduser($username, $userpass)
                {
                        global $quota_data;
                        if ($this->domain=="")
                        {
                                return array(1, "Empty domain");
                        }
                        if ($this->domainpass=="")
                        {
                                return array(1, "Empty domain password");
                        }
                        if ($username=="")
                        {
                                return array(1, "Empty username");
                        }
                        if ($userpass=="")
                        {
                                return array(1, "No user password supplied");
                        }
                        $command=array("adduser2", $this->domain, $username, 
$this->domainpass, $userpass, $username);
                        return $this->vm_daemon_raw($command);
                }

                /* vdeluser, takes domain name, password, and username, returns 
an array
        consisting of an integer exit code and message. */

                function vdeluser($username)
                {
                        if ($this->domain=="")
                        {
                                return array(1, "Empty domain");
                        }
                        if ($this->domainpass=="")
                        {
                                return array(1, "Empty domain password");
                        }
                        if ($username=="")
                        {
                                return array(1, "Empty username");
                        }
                        $command=array("deluser", $this->domain, $username, 
$this->domainpass);
                        return $this->vm_daemon_raw($command);
                }

                /* vchpass, takes domain name, password, username and a new 
password,
        returns an array consisting of an integer exit code and message. Scripts
        allowing users to change their own passwords should check the password
        was entered correctly by having the user enter it twice and checking
        these are equal*/

                function vchpass($username, $newpass)
                {
                        if ($this->domain=="")
                        {
                                return array(1, "Empty domain");
                        }
                        if ($this->domainpass=="")
                        {
                                return array(1, "Empty domain password");
                        }
                        if ($username=="")
                        {
                                return array(1, "Empty username");
                        }
                        if ($newpass=="")
                        {
                                return array(1, "Empty new password");
                        }
                        $command=array("chattr", $this->domain, $username, 
$this->domainpass, "1", $newpass);
                        return $this->vm_daemon_raw($command);
                }
        }
?>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]