Author Topic: PostfixAdmin bridge  (Read 54072 times)

Offline JavierF

  • Newbie
  • *
  • Posts: 1
LDAP integration
« Reply #15 on: November 07, 2008, 03:35:35 PM »
Hi Folks,

Sorry to dredge this thread up from the dead, but I've put together something that folks might find handy.

First, many thanks to whomever put together the RCPFA patches, and of course to the entire RC team.

I was excited when I saw this, as vacations and forwarding are operations I found myself needing to implement for our users.  However, my setup doesn't really have room for PostFix Admin; I'm using Postfix and Dovecot with LDAP as a back-end for authentication and storage of things like forwarding addresses and vacation messages.

To that end, utilizing the extra functionality provided by RCPFA and based on the object/function calls in pfa_*.inc, I wrote a quick-n-dirty "PFA" class that can be dropped in to func.inc to provide LDAP interaction.

Please excuse the messy code; I'm sure some of this could be tightened up significantly.  I'm more of a perl hacker than a PHP one.

Code: [Select]

// Define a class called 'pfa' to handle vacations and forwards
class pfa {
  var $ldaprdn = 'cn=admin,dc=domain,dc=com';
  var $ldappass = 'secret';
  var $ldapbase = 'ou=mail,dc=domain,dc=com';

  function update_vacation($u, $a, $s, $t) {
    if ($a == 1) { $a = "TRUE"; } else { $a = "FALSE"; }

    $ldap = ldap_connect("localhost")
or die("could not connect to ldap server");

    if ($ldap) {
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
$ldapbind = ldap_bind($ldap, $this->ldaprdn, $this->ldappass);
        $sr = ldap_search($ldap, $this->ldapbase, "(&(objectClass=VirtualMailAccount)(mail=$u))");
$ent = ldap_get_entries($ldap, $sr);
$dn = $ent[0]["dn"];
$userdata = array();
$userdata["vacationActive"] = $a;
$userdata["vacationInfo"] = $t;
ldap_modify($ldap, $dn, $userdata) or die("Unable to modify:" . ldap_error($ldap));
ldap_close($ldap);
return true;
    } else {
return false;
    }

  }

  function get_vacation($u) {
   
    // Fetch current values from LDAP
    $ldap = ldap_connect("localhost") or die ("No LDAP connect");
    ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
    $ldapbind = ldap_bind($ldap, $this->ldaprdn, $this->ldappass);
    $filter = "(&(objectClass=VirtualMailAccount)(mail=$u))";
    $results = array("vacationActive", "vacationInfo");
    $sr = ldap_search($ldap, $this->ldapbase, $filter, $results);
    $entries = ldap_get_entries($ldap, $sr);
   
    $active = $entries[0]["vacationactive"][0];
    $text = $entries[0]["vacationinfo"][0];
   
    if ($active == "TRUE") { $active = 1; } else { $active = 0; }
 
    $retval['active'] = $active;
    $retval['subject'] = ''; // Subject not implemented in my LDAP
    $retval['body'] = $text;

    ldap_unbind($ldap);
    return $retval;
  }

  function update_forwarding($u, $alias, $local) {
    $alias = rtrim($alias);
   
    // $alias will be a string with \ns. If it is empty, set forwardActive to false.
    // otherwise set forwardActive=true.
    // if Local is true, be sure to tack on their local mail address to the
    // array when it goes into LDAP.

    // If $alias is empty we need to disable forwarding; likewise if it is non-empty
    // we need to ensure forwarding is enabled.
    if (strlen($alias) < 5) {
$forwarding = &quot;FALSE&quot;;
    } else {
$forwarding = &quot;TRUE&quot;;
    }

    $fwds = explode(&quot;\n&quot;, $alias);

    // If we get 'true' for $local, then we need to tack on the user's email address.
    if ($local == &quot;true&quot;) {
      $fwds[] = $u;
    }

    $ldap = ldap_connect(&quot;localhost&quot;)
        or die(&quot;could not connect to ldap server&quot;);

    if ($ldap) {
        ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
        $ldapbind = ldap_bind($ldap, $this->ldaprdn, $this->ldappass);
        $sr = ldap_search($ldap, $this->ldapbase, &quot;(&(objectClass=VirtualMailAccount)(mail=$u))&quot;);
        $ent = ldap_get_entries($ldap, $sr);
        $dn = $ent[0][&quot;dn&quot;];
        $userdata = array();
if ($forwarding == &quot;TRUE&quot;) { $userdata[&quot;mailForward&quot;] = $fwds; }
$userdata[&quot;forwardActive&quot;] = $forwarding;
        ldap_modify($ldap, $dn, $userdata) or die(&quot;Unable to modify:&quot; . ldap_error($ldap));
        ldap_close($ldap);
        return true;
    } else {
        return false;
    }

  }

  function get_forwarding($u) {
    // LDAP fetching for forwarding stuff

    $ldap = ldap_connect(&quot;localhost&quot;) or die (&quot;No LDAP connect&quot;);
    ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
    $ldapbind = ldap_bind($ldap, $this->ldaprdn, $this->ldappass);
    $filter = &quot;(&(objectClass=VirtualMailAccount)(mail=$u))&quot;;
    $results = array(&quot;mailForward&quot;, &quot;forwardActive&quot;);
    $sr = ldap_search($ldap, $this->ldapbase, $filter, $results);
    $entries = ldap_get_entries($ldap, $sr);

    $local = false;
    $fwds = &quot;&quot;;

    if ($entries[0][&quot;forwardactive&quot;][0] == &quot;FALSE&quot;) {
$retval['aliases'] = '';
$retval['local'] = true;
ldap_unbind($ldap);
return $retval;
    }

    foreach ($entries[0][&quot;mailforward&quot;] as $address) {
if ($address == $u) {
 $local = true;
}
elseif (is_int($address)) { continue; }
else {
 $fwds .= $address . &quot;\n&quot;;
}
    }

    // Kill any lingering \ns at the end
    $fwds = rtrim($fwds);
    ldap_unbind($ldap);
    $retval['aliases'] = $fwds;
    $retval['local'] = $local;

    return $retval;
  }  

}


And for reference, here's what a record in my LDAP schema would look like:

Code: [Select]

accountActive: TRUE
cn: jrandom
delete: FALSE
gidNumber: 100
mail: jrandomhacker@local.domain
mailbox: jrandomhacker
uid: jrandomhacker@local.domain
uidNumber: 1234
userPassword:: {SSHA}foobarbaz
username: jrandomhacker
objectClass: VirtualMailAccount
objectClass: top
objectClass: shadowAccount
objectClass: posixAccount
gecos: J. Random Hacker
vacationActive: FALSE
vacationInfo: Not here, go away.
mailForward: username@remote.domain
forwardActive: FALSE


As you can see from the LDAP record and the code, I store whether or not vacation/forwarding is active with a pair of binary records, which Postfix then uses - along with the values of mailForward - to either redirect the email or send it to gnarwl for an auto-respond.

I haven't implemented password changing as there is another tool our users are meant to use for that, but you can see how it would be relatively easy to add.

Anyway, if anyone has any suggestions or questions, please let me know.

nejko

  • Guest
RCPFA 1.0.4 released
« Reply #16 on: November 19, 2008, 05:18:46 AM »
Hello,

RCPFA is now compatible with RoundCube 0.2beta. See RCPFA | Nejko’s randomness

Bye,
Nejc

Offline lostdragon

  • Newbie
  • *
  • Posts: 3
PostfixAdmin bridge
« Reply #17 on: November 20, 2008, 06:27:22 AM »
Excuse for my English...
Who be did registration for RounCube with use PostfixAdmin?

nejko

  • Guest
PostfixAdmin bridge
« Reply #18 on: November 20, 2008, 08:40:07 PM »
Quote from: lostdragon;15352
Excuse for my English...
Who be did registration for RounCube with use PostfixAdmin?


I don't understand the question. I wrote the RCPFA, if that's what you're asking.

Bye,
Nejc

Offline lostdragon

  • Newbie
  • *
  • Posts: 3
PostfixAdmin bridge
« Reply #19 on: December 05, 2008, 02:28:52 PM »
Quote from: nejko;15361
I don't understand the question. I wrote the RCPFA, if that's what you're asking.


It is necessary to make registration of accounts, using for connection given postfixadmin
Probably so will be more correct:-[

Offline lord2y

  • Newbie
  • *
  • Posts: 1
PostfixAdmin bridge
« Reply #20 on: January 06, 2009, 02:26:39 PM »
Hi all.

I downloaded the latest version 1.0.4 of RCPFA and the 0.2-stable to RoundCube but the patch does not work.
The tabs are unusable.
During patch I retrive an error on file apps.js.
In the pacth file (app.js.diff) I noticed that refers to another roundcube's version; 0not to the 0.2.
Someone managed to make it work?
Thank you.

Offline twiddler

  • Newbie
  • *
  • Posts: 1
PostfixAdmin bridge
« Reply #21 on: January 08, 2009, 09:25:07 AM »
Quote from: lord2y;16062
Hi all.

I downloaded the latest version 1.0.4 of RCPFA and the 0.2-stable to RoundCube but the patch does not work.
The tabs are unusable.
During patch I retrive an error on file apps.js.
In the pacth file (app.js.diff) I noticed that refers to another roundcube's version; 0not to the 0.2.
Someone managed to make it work?
Thank you.


I to upgrade to stable and the plugins don't work anymore... :(

Offline ashway

  • Newbie
  • *
  • Posts: 1
PostfixAdmin bridge
« Reply #22 on: January 29, 2009, 06:49:13 PM »
Quote from: twiddler;16151
I to upgrade to stable and the plugins don't work anymore... :(

I have already adapted version 1.0.4 to work with RC 0.2-stable.
See attachment.

To nejko:
---------
In 0.2-stable all java scripts are shrinked with ShrinkSafe | The Dojo Toolkit, original files have additional extension .src.

So, there are several ways to solve this:
1. Rename app.js.src to app.js, apply patch, shrink it.
2. Use patch, that patches shrinked version of app.js. I have included it in rcpfa-104-fixed.tar.gz.
3. Deploy patched version of app.js instead of patch.

I think you should choose the way and release a bugfix version 1.0.5.
« Last Edit: January 30, 2009, 05:24:15 AM by ashway »

Offline schickel

  • Newbie
  • *
  • Posts: 5
PostfixAdmin bridge
« Reply #23 on: January 30, 2009, 04:13:08 AM »
Hi ashway,

Quote from: ashway;16779
I have already adapted version 1.0.4 to work with RC 0.2-stable.
See attachment.

...



this work for me - thanks.

nejko

  • Guest
Rcpfa 1.0.5
« Reply #24 on: January 31, 2009, 06:07:06 PM »
Hey,

the 1.0.5 version makes RCPFA compatible with RC 0.2-stable. You can get it here RCPFA | Nejko's randomness.

Bye,
Nejc

Offline sh0x

  • Newbie
  • *
  • Posts: 2
Tabs don't work in firefox
« Reply #25 on: February 18, 2009, 12:41:36 AM »
Hi I'm running RCPFA 1.0.5 with RC 0.2-stable and it works great on my setup with postfixadmin, however the tabs don't seem to work in firefox. They work within IE but in firefox the tabs are there but when clicking on them nothing happens even though I can type in the url to the tabs and the page loads

Like if I change the URL to ?_task=vacation it'll load that page in firefox, but it doesn't change pages when I click the new tabs vacation, password, and forwarding.

Can someone confirm if the tabs work for them in firefox? I'm using firefox 3.0.6.

Thanks.

Offline konst

  • Newbie
  • *
  • Posts: 1
PostfixAdmin bridge
« Reply #26 on: March 18, 2009, 03:48:10 AM »
I have problem with patching app.js for roundcube 0.2.1 and rcpfa 1.0.5 could anyone share  patched app.js? :)

Offline iyuja

  • Newbie
  • *
  • Posts: 1
PostfixAdmin bridge
« Reply #27 on: March 22, 2009, 03:53:27 PM »
Quote from: nejko;16811
Hey,

the 1.0.5 version makes RCPFA compatible with RC 0.2-stable. You can get it here RCPFA | Nejko's randomness.

Bye,
Nejc


hi nejko, is it possible to have the non-shrinked version of the 105 patch?  i'm trying to generate a patch to use managesieve and rcpfa with roundcube, and without the .src it gets really complicated.

Offline climaxy

  • Newbie
  • *
  • Posts: 9
PostfixAdmin bridge
« Reply #28 on: March 31, 2009, 03:29:20 AM »
Will there also be an updated version released which is working with the current stable version 0.2.1?
I'd really like to try out this plugin!!

Offline danilka7

  • Newbie
  • *
  • Posts: 1
Help me please
« Reply #29 on: April 01, 2009, 08:28:45 AM »
When RCPFA return "Vacation" I receive next mail:

=========================================================
This is the mail system at host host.name.

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to postmaster.

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

                  The mail system

(expanded from user@host.name>): bad address
   syntax

Final-Recipient: rfc822; user#host.name@
Original-Recipient: rfc822;user@host.name
Action: failed
Status: 5.1.3
Diagnostic-Code: X-Postfix; bad address syntax


---------- Пересылаемое сообщение ----------
From: XXX
To: user@host.name
Date: Wed, 1 Apr 2009 12:57:48 +0300
Subject: Test!
Test!
=========================================================

What am I doing wrong.
Thanks.