index fb5209f60ae50ee3277f0d0231c3e31ef2e9f2a6..03c9987d1affa5473b0e2659ecc479fc6ec661a5 100644 (file)
class mailgroup extends plugin
{
/* CLI vars */
- var $cli_summary= "Manage mail groups/shared folders";
- var $cli_description= "Some longer text\nfor help";
- var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
- var $method= "mailMethod";
-
- /* plugin specific values */
- var $mail= "";
- var $uid= "";
- var $cn= "";
- var $gosaMailAlternateAddress= array();
- var $gosaMailForwardingAddress= array();
- var $gosaMailDeliveryMode= "[L ]";
- var $gosaMailServer= "";
- var $gosaMailQuota= "";
- var $gosaMailMaxSize= "";
- var $gosaVacationMessage= "";
- var $gosaSpamSortLevel= "";
- var $gosaSpamMailbox= "";
- var $gosaSharedFolderTarget;
- var $quotaUsage= 0;
- var $forward_dialog= FALSE;
- var $members= array();
- var $mailusers= array();
- var $perms= array();
- var $imapacl= array('anyone' => 'p', '%members%' => 'lrsp', '' => 'p');
- var $mmethod= "";
+ var $cli_summary = "Manage mail groups/shared folders";
+ var $cli_description = "Some longer text\nfor help";
+ var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
+
+ var $uid = ""; // User id
+ var $cn = ""; // cn
+ var $orig_cn = ""; // cn
+
+ var $method = "mailMethod"; // Used Mail method
+ var $mmethod = ""; // Contains the gosa.conf MAILMETHOD
+ var $mail = ""; // Default mail address
+
+ var $gosaMailAlternateAddress = array(); // Set default Alternate Mail Adresses to empty array
+ var $gosaMailForwardingAddress = array(); // Forwarding also empty
+
+ var $gosaMailServer = ""; // Selected mailserver
+ var $gosaMailQuota = ""; // Defined Quota
+ var $quotaUsage = 0; // Currently used quota
+
+ var $gosaVacationMessage = ""; // Vocation message
+
+ var $imapacl = array('anyone' => 'p', // Set acls for everyone
+ '%members%' => 'lrsp', // %members% are all group-members
+ '' => 'p'); // Every user added gets this right
+
+
+ var $gosaSpamSortLevel = "";
+ var $gosaSpamMailbox = "";
+ var $gosaSharedFolderTarget ;
+
+ var $forward_dialog = FALSE;
+
+ var $members = array(); // Group members
+
+ var $mailusers = array();
+ var $perms = array();
+ var $gosaMailDeliveryMode = "[L ]"; //
+ var $gosaMailMaxSize = ""; //
+
+ var $remove_folder_from_imap = true;
/* Helper */
var $indexed_acl= array();
var $indexed_user= array();
/* attribute list for save action */
- var $attributes= array("mail", "gosaMailServer", "gosaMailQuota", "gosaMailMaxSize","gosaMailAlternateAddress","gosaMailForwardingAddress",
- "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox","acl","gosaSharedFolderTarget",
- "gosaVacationMessage");
- var $objectclasses= array("gosaMailAccount");
+ var $attributes= array( "mail", "gosaMailServer", "gosaMailQuota", "gosaMailMaxSize",
+ "gosaMailAlternateAddress", "gosaMailForwardingAddress",
+ "gosaMailDeliveryMode", "gosaSpamSortLevel", "gosaSpamMailbox",
+ "acl","gosaSharedFolderTarget", "gosaVacationMessage");
+ var $objectclasses= array("gosaMailAccount");
+ var $CopyPasteVars = array("quotaUsage","imapacl");
- /* constructor, if 'dn' is set, the node loads the given
- 'dn' from LDAP */
function mailgroup ($config, $dn= NULL, $ui= NULL)
{
- /* Configuration is fine, allways */
- $this->config= $config;
-
- /* Load bases attributes */
+ /* Initialise all available attributes ... if possible
+ */
plugin::plugin($config, $dn);
- /* Set mailMethod to the one defined in gosa.conf */
+ $this->orig_cn = $this->cn;
+
+ /* Set mailMethod to the one defined in gosa.conf
+ */
if (isset($this->config->current['MAILMETHOD'])){
$this->mmethod= $this->config->current['MAILMETHOD'];
}
+ /* Check if selected mail method exists
+ */
if (class_exists("mailMethod$this->mmethod")){
$this->method= "mailMethod$this->mmethod";
} else {
print_red(sprintf(_("There is no mail method '%s' specified in your gosa.conf available."), $this->mmethod));
}
- /* Load Mailserver string, only in case of kolab ???? */
- if(preg_match("/kolab/i",$this->mmethod)){
- if(isset($this->attrs['gosaMailServer'][0])){
- $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
- }
- }
+ /* Load Mailserver
+ */
+ if(isset($this->attrs['gosaMailServer'][0])){
+ $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
+ }
- /* Convert cn to uid in case of existing entries */
+ /* Convert cn to uid in case of existing entry
+ */
if (isset($this->attrs['cn'][0])){
$this->uid= $this->attrs['cn'][0];
}
- if ($dn != NULL){
- /* Load attributes containing arrays */
+ /* If this ins't new mailgroup, read all required data from ldap
+ */
+ if (($dn != "new")&&($dn != NULL)){
+
+ /* Load attributes which represent multiple entries
+ */
foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
$this->$val = array();
if (isset($this->attrs["$val"]["count"])){
}
}
- /* Only do IMAP actions if gosaMailServer attribute is set */
+ /* Only do IMAP actions if gosaMailServer attribute is set
+ */
if (isset ($this->attrs["gosaMailServer"][0])){
+
+ /* Create new instance of our defined mailclass
+ */
$method= new $this->method($this->config);
+
if ($method->connect($this->attrs["gosaMailServer"][0])){
- $quota= $method->getQuota($this->uid);
+
/* Maybe the entry is not saved in new style, get
permissions from IMAP and convert them to acl attributes */
/* Highest count wins as %members%, remove all members
with the same acl */
- $this->imapacl['%members%']= $leader;
+ if(!empty($leader)){
+ $this->imapacl['%members%']= $leader;
+ }
foreach ($this->imapacl as $user => $acl){
if ($this->acl == $leader && in_array($user, $this->attrs['memberUid'])){
unset($this->imapacl[$user]);
}
}
- }
+ } // ENDE ! isset ($this->attrs['acl'])
+
+ /* Adapt attributes if needed */
+ $method->fixAttributesOnLoad($this);
+
+ /* get Quota */
+ $quota= $method->getQuota($this->uid);
/* Update quota values */
- if ($quota['gosaMailQuota'] == 2147483647){
- $this->quotaUsage= "";
- $this->gosaMailQuota= "";
- } else {
- $this->quotaUsage= $quota['quotaUsage'];
- $this->gosaMailQuota= $quota['gosaMailQuota'];
+ if(is_array($quota)){
+ if ($quota['gosaMailQuota'] == 2147483647){
+ $this->quotaUsage= "";
+ $this->gosaMailQuota= "";
+ } else {
+ $this->quotaUsage= $quota['quotaUsage'];
+ $this->gosaMailQuota= $quota['gosaMailQuota'];
+ }
+ }else{
+ $this->quotaUsage = "";
+ $this->gosaMailQuota = "";
+// print_red(sprintf(_("Can't get quota information for '%s'."),$this->uid));
}
$method->disconnect();
- }
+ } // ENDE $method->connect($this->attrs["gosaMailServer"][0])){
+
+ } // ENDE gosaMailServer
+
+ } // ENDE dn != "new"
- /* Adapt attributes if needed */
- $method->fixAttributesOnLoad($this);
- }
- }
/* Get global filter config */
if (!is_global("gmailfilter")){
$tmp = array();
if(preg_match("/kolab/i",$this->mmethod)){
$ldap = $this->config->get_ldap_link();
+
if (isset($this->attrs['acl'])){
+
for ($i= 0; $i<$this->attrs['acl']['count']; $i++){
list($user, $permission)= split(' ', $this->attrs['acl'][$i]);
/* Get all user permissions sorted by acl, to detect the most used acl
This acl is then used for %members%
*/
- $tmp[$permission][] = $user;
+ if ($user != "anyone" && $user != "%members%"){
+ $tmp[$permission][] = $user;
+ }
/* There is an entry in $this->imapacl like this this ...
$this->attrs['imapacl']['anyone'] = "p";
foreach($tmp as $acl => $user){
$tmp2[count($tmp[$acl])]=$acl;
}
- /* Most used at last */
+ /* Most used at last
+ */
ksort($tmp2);
+
+ /* Assign last (most used acl) to %members% acl
+ */
+ $str = array_pop($tmp2);
+ if(!empty($str)) {
+ $this->imapacl['%members%']=$str;
+ }
- /* Assign last (most used acl) to %members% acl */
- $this->imapacl['%members%']=array_pop($tmp2);
-
- /* Open ldap connection */
+ /* Open ldap connection
+ */
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']);
foreach($this->imapacl as $mail => $permission){
$ldap->search("(&(objectClass=person)(mail=".$mail."))",array("uid"));
$atr = $ldap->fetch();
- if((isset($atr['uid'][0]))&&(in_array($atr['uid'][0],$this->attrs['memberUid']))&&($permission == $this->imapacl['%members%'])){
- unset($this->imapacl[$mail]);
+ if((isset($this->attrs['memberUid'])) && (is_array($this->attrs['memberUid']))){
+ if((isset($atr['uid'][0]))&&(in_array($atr['uid'][0],$this->attrs['memberUid']))&&($permission == $this->imapacl['%members%'])){
+ unset($this->imapacl[$mail]);
+ }
}
}
-
/* Append an empty entry, for special acl handling */
if(count($this->imapacl)==2){
$this->imapacl[''] ="";
}
- }else{
+
+ }else{ // Not kolab
/* Load permissions */
if (isset($this->attrs['acl'])){
for ($i= 0; $i<$this->attrs['acl']['count']; $i++){
}
}
}
+
+ /* Load Mailserver
+ */
+ if(isset($this->attrs['gosaMailServer'][0])){
+ $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
+ }
/* Fill translations */
$this->perms["lrs"]= _("read");
$this->perms["lrsp"]= _("post");
$this->perms["p"]= _("external post");
$this->perms["lrsip"]= _("append");
$this->perms["lrswipcd"]= _("write");
+ $this->perms[""]= _("none");
}
-
function execute()
{
/* Call parent execute */
/* Load templating engine */
$smarty= get_smarty();
+
+ /* Assign acls */
+ $tmp = $this->plInfo();
+ foreach($tmp['plProvidedAcls'] as $name => $translation) {
+ $smarty->assign($name."ACL",$this->getacl($name));
+ }
+
if ($_SESSION['js']==FALSE){
$smarty->assign("javascript", "false");
} else {
}
/* Do we need to flip is_account state? */
- if (isset($_POST['modify_state'])){
- $this->is_account= !$this->is_account;
+ if(isset($_POST['modify_state'])){
+ if($this->is_account && $this->acl_is_removeable()){
+ $this->is_account= FALSE;
+ }elseif(!$this->is_account && $this->acl_is_createable()){
+ $this->is_account= TRUE;
+ }
}
+ $display = "";
+
/* Do we represent a valid account? */
if (!$this->is_account && $this->parent == NULL){
- $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
+
+ $display.= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
_("This 'dn' has no valid mail extensions.")."</b>";
return ($display);
}
$display= "";
if ($this->parent != NULL){
if ($this->is_account){
- $display= $this->show_header(_("Remove mail account"),
+ $display.= $this->show_disable_header(_("Remove mail account"),
_("This account has mail features enabled. You can disable them by clicking below."));
} else {
- $display= $this->show_header(_("Create mail account"),
+ $display.= $this->show_enable_header(_("Create mail account"),
_("This account has mail features disabled. You can enable them by clicking below."));
+
+ /* Show checkbox that allows us to remove imap entry too*/
+ if($this->initially_was_account){
+ $c = "";
+ if($this->remove_folder_from_imap){
+ $c= " checked ";
+ }
+ $display .= "<h2>Shared folder delete options</h2>
+ <input class='center' type='checkbox' name='remove_folder_from_imap' value='1' ".$c."
+ title='"._("Remove shared folder from mail server database when entry gets removed in LDAP")."'>";
+ $display .= _("Remove the shared folder and all its contents after saving this account");
+ }
return ($display);
}
}
/* Add ACL? */
- foreach ($this->indexed_user as $nr => $user){
- if (isset($_POST["add_$nr"])){
- $this->imapacl[""]= "l";
- }
- if (isset($_POST["del_$nr"])){
- unset ($this->imapacl[$user]);
+ if($this->acl_is_writeable("acl")){
+ foreach ($this->indexed_user as $nr => $user){
+ if (isset($_POST["add_$nr"])){
+ $this->imapacl[""]= "l";
+ }
+ if (isset($_POST["del_$nr"])){
+ unset ($this->imapacl[$user]);
+ }
}
}
/* Trigger forward add dialog? */
- if (isset($_POST['add_local_forwarder'])){
- $this->forward_dialog= TRUE;
- $this->dialog= TRUE;
+ if($this->acl_is_writeable("gosaMailForwardingAddress")){
+ if (isset($_POST['add_local_forwarder'])){
+ $this->forward_dialog= TRUE;
+ $this->dialog= TRUE;
+ }
}
/* Cancel forward add dialog? */
- if (isset($_POST['add_locals_cancel'])){
- $this->forward_dialog= FALSE;
- $this->dialog= FALSE;
+ if($this->acl_is_writeable("gosaMailForwardingAddress")){
+ if (isset($_POST['add_locals_cancel'])){
+ $this->forward_dialog= FALSE;
+ $this->dialog= FALSE;
+ }
}
/* Finished adding of locals? */
- if (isset($_POST['add_locals_finish'])){
- if (count ($_POST['local_list']) &&
- chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
+ if ((isset($_POST['add_locals_finish'])) && ($this->acl_is_writeable("gosaMailForwardingAddress"))) {
+ if (count ($_POST['local_list']) && $this->acl_is_writeable("gosaMailForwardingAddress")){
/* Walk through list of forwarders, ignore own addresses */
foreach ($_POST['local_list'] as $val){
}
/* Add forward email addresses */
- if (isset($_POST['add_forwarder'])){
+ if ((isset($_POST['add_forwarder'])) && ($this->acl_is_writeable("gosaMailForwardingAddress"))){
if ($_POST['forward_address'] != ""){
/* Valid email address specified? */
} else {
/* Add it */
- if (chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
+ if ($this->acl_is_writeable("gosaMailForwardingAddress")){
$this->addForwarder ($address);
}
}
/* Delete forward email addresses */
- if (isset($_POST['delete_forwarder'])){
- if (count($_POST['forwarder_list'])
- && chkacl ($this->acl, "gosaMailForwardingAddress") == ""){
+ if (isset($_POST['delete_forwarder']) && ($this->acl_is_writeable("gosaMailForwardingAddress"))){
+ if (count($_POST['forwarder_list'])&& $this->acl_is_writeable("gosaMailForwardingAddress")){
$this->delForwarder ($_POST['forwarder_list']);
}
/* Add alternate email addresses */
if (isset($_POST['add_alternate'])){
- if ($_POST['alternate_address'] != "" &&
- chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
+ if ($_POST['alternate_address'] != "" && $this->acl_is_writeable("gosaMailAlternateAddress")){
if (!is_email($_POST['alternate_address'])){
print_red (_("You're trying to add an invalid email address to the list of alternate addresses."));
}
/* Delete alternate email addresses */
- if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){
- if (count($_POST['alternates_list']) &&
- chkacl ($this->acl, "gosaMailAlternateAddress") == ""){
-
- $this->delAlternate ($_POST['alternates_list']);
+ if($this->acl_is_writeable("gosaMailAlternateAddress")){
+ if (isset($_POST['delete_alternate']) && isset ($_POST['alternates_list'])){
+ if (count($_POST['alternates_list']) && $this->acl_is_writeable("gosaMailAlternateAddress")){
+ $this->delAlternate ($_POST['alternates_list']);
+ }
}
}
$filter.= "(!(|$exclude))";
}
- $acl= array($this->config->current['BASE'] => ":all");
- $res= get_list($acl, "(&(objectClass=gosaMailAccount)$filter)", TRUE, $gmailfilter['depselect'], array("sn", "mail", "givenName"), TRUE);
+ $res= get_list("(&(objectClass=gosaMailAccount)$filter)", "users", $gmailfilter['depselect'],
+ array("sn", "mail", "givenName"), GL_SUBSEARCH | GL_SIZELIMIT);
$ldap->cd($gmailfilter['depselect']);
$ldap->search ("(&(objectClass=gosaMailAccount)$filter)", array("sn", "mail", "givenName"));
error_reporting (0);
}
/* Assemble normal permissions */
- $smarty->assign("permissionsACL", chkacl($this->acl, "permissions"));
if (isset($this->imapacl['anyone'])){
$smarty->assign("default_permissions", $this->imapacl['anyone']);
}
}
/* Assemble extra attributes */
- $perm= chkacl($this->acl, "permissions");
+ $perm= $this->getacl( "permissions");
$tmp= "";
$nr= 0;
$count= count($this->imapacl);
$this->indexed_user= array();
$this->indexed_acl= array();
foreach($this->imapacl as $user => $acl){
+
+ /* Add additional acl settings */
if ($user != "anyone" && $user != "%members%"){
- $tmp.= "<tr><td><input name=\"user_$nr\" size=20 maxlength=60 ".
- "value=\"$user\" $perm></td><td><select size=\"1\" name=\"perm_$nr\" $perm>";
- foreach ($this->perms as $key => $value){
- if ($acl == $key){
- $tmp.= "<option value=$key selected>$value</option>";
- } else {
- $tmp.= "<option value=$key>$value</option>";
+
+ $Dis = "";
+ if(!preg_match("/w/",$perm)){
+ $Dis = " disabled ";
+ }
+
+ /* Reset given Acls to ensure that nobody can read username and acls if not allwoed */
+ if(!preg_match("/r/",$perm)){
+ $user = "";
+ $nr = "none";
+ $key = "none";
+ }
+
+ $tmp.= "<tr>
+ <td>
+ <input name=\"user_$nr\" size=20 maxlength=60 value=\"$user\" ".$Dis.">
+ </td>
+ <td>
+ <select size=\"1\" name=\"perm_$nr\" ".$Dis.">";
+
+ /* Add acl options for this additional acl setting */
+ if(preg_match("/r/",$perm)){
+ foreach ($this->perms as $key => $value){
+ if ($acl == $key){
+ $tmp.= "<option value=$key selected>$value</option>";
+ } else {
+ $tmp.= "<option value=$key>$value</option>";
+ }
}
}
$tmp.= "</select> ";
+
+
+
if ($nr == $count - 1){
- $tmp.= "<input type=submit value=\""._("Add")."\" ".
- "name=\"add_$nr\" $perm>";
+ if($this->acl_is_writeable("acl")){
+ $tmp.= "<input type=submit value=\""._("Add")."\" ".
+ "name=\"add_$nr\" >";
+ }
}
if ($count > 3){
- $tmp.= "<input type=submit value=\""._("Remove")."\" ".
- "name=\"del_$nr\" $perm></td></tr>";
+ if($this->acl_is_writeable("acl")){
+ $tmp.= "<input type=submit value=\""._("Remove")."\" ".
+ "name=\"del_$nr\" ></td></tr>";
+ }
}
}
$this->indexed_user[$nr]= $user;
foreach(array("gosaMailServer", "gosaMailQuota", "perms", "mail",
"gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
$smarty->assign("$val", $this->$val);
- $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
}
if (is_numeric($this->gosaMailQuota) && $this->gosaMailQuota != 0){
- $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota),100,15,true));
- $smarty->assign("quotadefined", "true");
+ if($this->acl_is_readable("gosaMailQuota")){
+ $smarty->assign("quotausage", progressbar(round(($this->quotaUsage * 100)/ $this->gosaMailQuota),100,15,true));
+ $smarty->assign("quotadefined", "true");
+ }else{
+ $smarty->assign("quotadefined", "true");
+ $smarty->assign("quotausage", "-");
+ }
} else {
$smarty->assign("quotadefined", "false");
}
*/
if(isset($this->config->current['MAILMETHOD'])&&preg_match("/kolab/i",$this->config->current['MAILMETHOD'])){
$this->attributes[]="acl";
- $this->attributes[]="kolabHomeServer";
$this->objectclasses[] = "kolabSharedFolder";
}
/* include global link_info */
$this->attrs['gosaMailForwardingAddress']= array();
$this->attrs['gosaSharedFolderTarget']= array();
- /* Keep uid */
- unset ($this->attrs['uid']);
- $ldap->cd($this->dn);
- $this->cleanup();
- $ldap->modify ($this->attrs);
-
- show_ldap_error($ldap->get_error());
-
/* Connect to IMAP server for account deletion */
- if ($this->is_account){
+ if ($this->initially_was_account){
+
$method= new $this->method($this->config);
- if ($method->connect($this->attrs["gosaMailServer"][0])){
+ $method->fixAttributesOnRemove($this);
+ if ($method->connect($this->gosaMailServer) && $this->remove_folder_from_imap){
+
/* Remove account from IMAP server */
$method->deleteMailbox($this->uid);
$method->disconnect();
}
- $method->fixAttributesOnRemove($this);
}
+ /* Keep uid */
+ unset ($this->attrs['uid']);
+
+ $ldap->cd($this->dn);
+ $ldap->modify ($this->attrs);
+ show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/mail with dn '%s' failed."),$this->dn));
/* Optionally execute a command after we're done */
$this->handle_post_events("remove");
/* Save data to object */
function save_object()
{
+
+ /* Check if user wants to remove the shared folder from imap too */
+ if($this->initially_was_account && !$this->is_account){
+ if(isset($_POST['remove_folder_from_imap'])){
+ $this->remove_folder_from_imap = true;
+ }else{
+ $this->remove_folder_from_imap = false;
+ }
+ }
+
/* Assemble mail delivery mode
The mode field in ldap consists of values between braces, this must
be called when 'mail' is set, because checkboxes may not be set when
I: Only insider delivery */
if (isset($_POST['mailedit'])){
- /* Save ldap attributes */
plugin::save_object();
- $tmp= "";
- if (!isset($_POST["drop_own_mails"])){
- $tmp.= "L";
- }
- if (isset($_POST["use_mailsize_limit"])){
- $tmp.= "R";
- }
- if (isset($_POST["use_spam_filter"])){
- $tmp.= "S";
- }
- if (isset($_POST["use_vacation"])){
- $tmp.= "V";
- }
- if (isset($_POST["own_script"])){
- $tmp.= "C";
+ $tmp= preg_replace("/[^a-z]/i","",$this->gosaMailDeliveryMode);
+
+ /* Handle delivery flags */
+ if($this->acl_is_writeable("gosaMailDeliveryModeL")){
+ if(!preg_match("/L/",$tmp) && !isset($_POST['drop_own_mails'])){
+ $tmp.="L";
+ }elseif(preg_match("/L/",$tmp) && isset($_POST['drop_own_mails'])){
+ $tmp = preg_replace("/L/","",$tmp);
+ }
}
- if (isset($_POST["only_local"])){
- $tmp.= "I";
+
+ $opts = array(
+ "R" => "use_mailsize_limit",
+ "S" => "use_spam_filter",
+ "V" => "use_vacation",
+ "C" => "own_script",
+ "I" => "only_local");
+
+ foreach($opts as $flag => $post){
+ if($this->acl_is_writeable("gosaMailDeliveryMode".$flag)){
+ if(!preg_match("/".$flag."/",$tmp) && isset($_POST[$post])){
+ $tmp.= $flag;
+ }elseif(preg_match("/".$flag."/",$tmp) && !isset($_POST[$post])){
+ $tmp = preg_replace("/".$flag."/","",$tmp);
+ }
+ }
}
- $tmp= "[$tmp]";
- if (chkacl ($this->acl, "gosaMailDeliveryMode") == ""){
- $this->gosaMailDeliveryMode= $tmp;
+ $tmp= "[$tmp]";
+ if ($this->gosaMailDeliveryMode != $tmp){
+ $this->is_modified= TRUE;
}
+ $this->gosaMailDeliveryMode= $tmp;
/* Collect data and re-assign it to the imapacl array */
- if (chkacl($this->acl, "permissions") == ""){
+ if ($this->acl_is_writeable("acl")){
$this->imapacl= array();
$this->imapacl['%members%']= $_POST['member_permissions'];
$this->imapacl['anyone']= $_POST['default_permissions'];
}
- /*
- Backup for function save
-Änderungen : fixAttributesOnStore($this) wurde erst nach dem this->cleanup();
-$ldap->modify
-Ausgeführt, deshalb wurden die gemappten Attribute auch nicht
-gespeichert.
-
-Von : Fabian Hickert
-Datum : 15.12.2005
-
-Alter Quellcode :
-
- /* Save data to LDAP, depending on is_account we save or delete * /
+ /* Save data to LDAP, depending on is_account we save or delete */
function save()
{
- $ldap= $this->config->get_ldap_link();
-
- /* Call parents save to prepare $this->attrs * /
- plugin::save();
-
- /* Save arrays * /
- $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
- $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
-
- /* Save shared folder target * /
- $this->attrs['gosaSharedFolderTarget']= "share+".$this->uid;
-
- /* Save acl's * /
- $this->attrs['acl']= array();
- foreach ($this->imapacl as $user => $acl){
- if ($user == ""){
- continue;
- }
- $this->attrs['acl'][]= "$user $acl";
- }
-
- /* Save data to LDAP * /
- $ldap->cd($this->dn);
- $this->cleanup();
- $ldap->modify ($this->attrs);
-
- show_ldap_error($ldap->get_error());
-
- /* Only do IMAP actions if we are not a template * /
- if (!$this->is_template){
- $method= new $this->method($this->config);
- $method->fixAttributesOnStore($this);
- if ($method->connect($this->gosaMailServer)){
- $method->updateMailbox($this->uid);
- $method->setQuota($this->uid, $this->gosaMailQuota);
-
-/* Exchange '%member%' pseudo entry * /
-$memberacl= $this->imapacl['%members%'];
-unset ($this->imapacl['%members%']);
-foreach ($this->members as $user){
-if (!isset($this->imapacl[$user])){
-$this->imapacl[$user]= $memberacl;
-}
-}
-
-$method->setSharedFolderPermissions($this->uid, $this->imapacl);
-$method->disconnect();
-}
-}
-
-/* Optionally execute a command after we're done * /
-if ($this->initially_was_account == $this->is_account){
-if ($this->is_modified){
-$this->handle_post_events("mofify");
-}
-} else {
-$this->handle_post_events("add");
-}
-}
-
-ENDE Alter Quellcode
- */
-
-
-
-
-
+ $ldap= $this->config->get_ldap_link();
+ $ldap->cd($this->config->current['BASE']);
+ /* Call parents save to prepare $this->attrs */
+ plugin::save();
+ /* Save arrays */
+ $this->attrs['gosaMailAlternateAddress'] = $this->gosaMailAlternateAddress;
+ $this->attrs['gosaMailForwardingAddress'] = $this->gosaMailForwardingAddress;
+ $this->attrs['gosaSharedFolderTarget'] = "share+".$this->uid;
-/* Save data to LDAP, depending on is_account we save or delete */
-function save()
-{
- $ldap= $this->config->get_ldap_link();
+ if(preg_match("/kolab/i",$this->mmethod)){
+ /* Save acl's */
+ $this->attrs['acl']= array();
+ foreach ($this->imapacl as $user => $acl){
+ if ($user == ""){
+ continue;
+ }
+ $ldap->search("(&(objectClass=person)(|(uid=".$user.")(mail=".$user.")))",array("mail"));
+ $mail = $ldap->fetch();
+ if($mail){
+ if(isset($mail['mail'][0])){
+ $this->attrs['acl'][]= $mail['mail'][0]." $acl";
+ }
+ }else{
+ $this->attrs['acl'][]= "$user $acl";
+ }
+ }
+ }else{
+ /* Save acl's */
+ $this->attrs['acl']= array();
+ foreach ($this->imapacl as $user => $acl){
+ if ($user == ""){
+ continue;
+ }
+ $this->attrs['acl'][]= "$user $acl";
+ }
+ }
- /* Call parents save to prepare $this->attrs */
- plugin::save();
+ /* Only do IMAP actions if we are not a template */
+ if(preg_match("/kolab/i",$this->mmethod)){
+ if (empty($this->gosaMailServer)||is_array($this->gosaMailServer)){
+ if(isset($this->attrs['gosaMailServer'][0])){
+ $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
+ }
+ }
+ }
- /* Save arrays */
- $this->attrs['gosaMailAlternateAddress']= $this->gosaMailAlternateAddress;
- $this->attrs['gosaMailForwardingAddress']= $this->gosaMailForwardingAddress;
- /* Save shared folder target */
- $this->attrs['gosaSharedFolderTarget']= "share+".$this->uid;
+ /* Exchange '%member%' pseudo entry */
+ $memberacl= $this->imapacl['%members%'];
- if(preg_match("/kolab/i",$this->mmethod)){
- /* Save acl's */
- $this->attrs['acl']= array();
- foreach ($this->imapacl as $user => $acl){
- if ($user == ""){
- continue;
- }
- $ldap->search("(&(objectClass=person)(uid=".$user."))",array("mail"));
- $mail = $ldap->fetch();
- if($mail){
- if(isset($mail['mail'][0])){
- $this->attrs['acl'][]= $mail['mail'][0]." $acl";
+ foreach ($this->members as $user){
+ if(preg_match("/kolab/i",$this->mmethod)){
+ $ldap->cd($this->config->current['BASE']);
+ $ldap->search("(&(objectClass=person)(|(mail=".$user.")(uid=".$user.")))",array("mail"));
+ $at = $ldap->fetch();
+ if(isset($at['mail'][0])){
+ $user = $at['mail'][0];
}
- }else{
- $this->attrs['acl'][]= "$user $acl";
+ }
+ if (!isset($this->imapacl[$user])){
+ $this->imapacl[$user]= $memberacl;
}
}
- }else{
- /* Save acl's */
- $this->attrs['acl']= array();
- foreach ($this->imapacl as $user => $acl){
- if ($user == ""){
+ $this->attrs['acl'] = array();
+
+
+ foreach($this->imapacl as $user => $acl){
+
+ /* Remove empty user entry, to avoid entry like this im imap
+ * "" lrs
+ */
+ if(empty($user)){
+ unset($this->imapacl[$user]);
+ }
+
+ /* Skip invalid values */
+ if(preg_match("/%members%/",$user) || empty($user)){
continue;
}
- $this->attrs['acl'][]= "$user $acl";
+
+ /* Append ldap acl entries */
+ $this->attrs['acl'][] = $user." ".$acl;
}
- }
- /* Only do IMAP actions if we are not a template */
- if(preg_match("/kolab/i",$this->mmethod)){
- if (empty($this->gosaMailServer)||is_array($this->gosaMailServer)){
- if(isset($this->attrs['gosaMailServer'][0])){
- $this->gosaMailServer = $this->attrs['gosaMailServer'][0];
+ if ((!$this->is_template)&&(!empty($this->gosaMailServer))){
+ $method= new $this->method($this->config);
+ $method->fixAttributesOnStore($this);
+ if (($method->connect($this->gosaMailServer))){
+ $method->updateMailbox($this->uid);
+ $method->setQuota($this->uid, $this->gosaMailQuota);
+ $method->setSharedFolderPermissions($this->uid, $this->imapacl);
+ $method->disconnect();
}
}
- }
- if ((!$this->is_template)&&(!empty($this->gosaMailServer))){
- $method= new $this->method($this->config);
- $method->fixAttributesOnStore($this);
- if ($method->connect($this->gosaMailServer)){
- $method->updateMailbox($this->uid);
- $method->setQuota($this->uid, $this->gosaMailQuota);
+ /* Save data to LDAP */
+ $ldap->cd($this->dn);
+ $this->cleanup();
+ $ldap->modify ($this->attrs);
+ show_ldap_error($ldap->get_error(), sprintf(_("Saving of groups/mail with dn '%s' failed."),$this->dn));
- /* Exchange '%member%' pseudo entry */
- $memberacl= $this->imapacl['%members%'];
- unset ($this->imapacl['%members%']);
- foreach ($this->members as $user){
- if (!isset($this->imapacl[$user])){
- $this->imapacl[$user]= $memberacl;
- }
+ /* Optionally execute a command after we're done */
+ if ($this->initially_was_account == $this->is_account){
+ if ($this->is_modified){
+ $this->handle_post_events("modify");
}
-
- $method->setSharedFolderPermissions($this->uid, $this->imapacl);
- $method->disconnect();
+ } else {
+ $this->handle_post_events("add");
}
}
- /* Save data to LDAP */
- $ldap->cd($this->dn);
- $this->cleanup();
- $ldap->modify ($this->attrs);
-
- show_ldap_error($ldap->get_error());
-
- /* Optionally execute a command after we're done */
- if ($this->initially_was_account == $this->is_account){
- if ($this->is_modified){
- $this->handle_post_events("mofify");
- }
- } else {
- $this->handle_post_events("add");
- }
-}
+ /* Check formular input */
+ function check()
+ {
+ $ldap= $this->config->get_ldap_link();
-/* Check formular input */
-function check()
-{
- $ldap= $this->config->get_ldap_link();
+ /* Call common method to give check the hook */
+ $message= plugin::check();
- $message= array();
+ if(!$this->is_account) return array();
+
+ //$message[] = $str;
- /* must: mail */
- if ($this->mail == ""){
- $message[]= _("The required field 'Primary address' is not set.");
- }
- if (!is_email($this->mail)){
- $message[]= _("Please enter a valid email addres in 'Primary address' field.");
- }
- $ldap->cd($this->config->current['BASE']);
- $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
- $this->mail."))(!(uid=".$this->cn."))(!(cn=".$this->cn.")))");
- if ($ldap->count() != 0){
- $message[]= _("The primary address you've entered is already in use.");
- }
+ /* must: mail */
+ if ($this->mail == ""){
+ $message[]= _("The required field 'Primary address' is not set.");
+ }
+ if (!is_email($this->mail)){
+ $message[]= _("Please enter a valid email addres in 'Primary address' field.");
+ }
+ $ldap->cd($this->config->current['BASE']);
+ $ldap->search ("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaMailAccount)(|(mail=".$this->mail.")(gosaMailAlternateAddress=".
+ $this->mail."))(!(uid=".$this->orig_cn."))(!(cn=".$this->orig_cn.")))");
+ if ($ldap->count() != 0){
+ $message[]= _("The primary address you've entered is already in use.");
+ }
+
+ /* Check quota */
+ if ($this->gosaMailQuota != '' && $this->acl_is_writeable("gosaMailQuota")){
+ if (!is_numeric($this->gosaMailQuota)) {
+ $message[]= _("Value in 'Quota size' is not valid.");
+ } else {
+ $this->gosaMailQuota= (int) $this->gosaMailQuota;
+ }
+ }
- /* Check quota */
- if ($this->gosaMailQuota != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
- if (!is_numeric($this->gosaMailQuota)) {
- $message[]= _("Value in 'Quota size' is not valid.");
- } else {
- $this->gosaMailQuota= (int) $this->gosaMailQuota;
+ /* Check rejectsize for integer */
+ if ($this->gosaMailMaxSize != '' && $this->acl_is_writeable("gosaMailQuota")){
+ if (!is_numeric($this->gosaMailMaxSize)){
+ $message[]= _("Please specify a vaild mail size for mails to be rejected.");
+ } else {
+ $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
+ }
}
- }
- /* Check rejectsize for integer */
- if ($this->gosaMailMaxSize != '' && chkacl ($this->acl, "gosaMailQuota") == ""){
- if (!is_numeric($this->gosaMailMaxSize)){
- $message[]= _("Please specify a vaild mail size for mails to be rejected.");
- } else {
- $this->gosaMailMaxSize= (int) $this->gosaMailMaxSize;
+ /* Need gosaMailMaxSize if use_mailsize_limit is checked */
+ if (is_integer(strpos($this->gosaMailDeliveryMode, "reject")) && $this->gosaMailMaxSize == ""){
+ $message[]= _("You need to set the maximum mail size in order to reject anything.");
}
- }
- /* Need gosaMailMaxSize if use_mailsize_limit is checked */
- if (is_integer(strpos($this->gosaMailDeliveryMode, "reject")) && $this->gosaMailMaxSize == ""){
- $message[]= _("You need to set the maximum mail size in order to reject anything.");
- }
+ if(ord($this->imapacl['anyone'][0])==194){
+ $message[] = _("Please choose valid permission settings. Default permission can't be emtpy.");
+ }
- if(ord($this->imapacl['anyone'][0])==194){
- $message[] = _("Please choose valid permission settings. Default permission can't be emtpy.");
- }
+ if(empty($this->gosaMailServer)){
+ $message[] = _("Please select a valid mail server.");
+ }
- if(empty($this->gosaMailServer)){
- $message[] = _("Please select a valid mail server.");
+ return ($message);
}
- return ($message);
-}
-
-/* Adapt from template, using 'dn' */
-function adapt_from_template($dn)
-{
- plugin::adapt_from_template($dn);
-
- foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
- $this->$val= array();
- if (isset($this->attrs["$val"]["count"])){
- for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
- $value= $this->attrs["$val"][$i];
- foreach (array("sn", "givenName", "uid") as $repl){
- if (preg_match("/%$repl/i", $value)){
- $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
+ /* Adapt from template, using 'dn' */
+ function adapt_from_template($dn)
+ {
+ plugin::adapt_from_template($dn);
+
+ foreach (array("gosaMailAlternateAddress", "gosaMailForwardingAddress") as $val){
+ $this->$val= array();
+ if (isset($this->attrs["$val"]["count"])){
+ for ($i= 0; $i<$this->attrs["$val"]["count"]; $i++){
+ $value= $this->attrs["$val"][$i];
+ foreach (array("sn", "givenName", "uid") as $repl){
+ if (preg_match("/%$repl/i", $value)){
+ $value= preg_replace ("/%$repl/i", $this->parent->$repl, $value);
+ }
}
+ array_push($this->$val, $value);
}
- array_push($this->$val, $value);
}
}
}
-}
-/* Add entry to forwarder list */
-function addForwarder($address)
-{
- $this->gosaMailForwardingAddress[]= $address;
- $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
+ /* Add entry to forwarder list */
+ function addForwarder($address)
+ {
+ $this->gosaMailForwardingAddress[]= $address;
+ $this->gosaMailForwardingAddress= array_unique ($this->gosaMailForwardingAddress);
- sort ($this->gosaMailForwardingAddress);
- reset ($this->gosaMailForwardingAddress);
- $this->is_modified= TRUE;
-}
+ sort ($this->gosaMailForwardingAddress);
+ reset ($this->gosaMailForwardingAddress);
+ $this->is_modified= TRUE;
+ }
-/* Remove list of addresses from forwarder list */
-function delForwarder($addresses)
-{
- $this->gosaMailForwardingAddress= array_remove_entries ($addresses,
- $this->gosaMailForwardingAddress);
- $this->is_modified= TRUE;
-}
+ /* Remove list of addresses from forwarder list */
+ function delForwarder($addresses)
+ {
+ $this->gosaMailForwardingAddress= array_remove_entries ($addresses,
+ $this->gosaMailForwardingAddress);
+ $this->is_modified= TRUE;
+ }
-function addAlternate($address)
-{
- $ldap= $this->config->get_ldap_link();
+ function addAlternate($address)
+ {
+ $ldap= $this->config->get_ldap_link();
- $address= strtolower($address);
+ $address= strtolower($address);
- /* Is this address already assigned in LDAP? */
- $ldap->cd ($this->config->current['BASE']);
- $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)".
- "(gosaMailAlternateAddress=$address)))");
+ /* Is this address already assigned in LDAP? */
+ $ldap->cd ($this->config->current['BASE']);
+ $ldap->search ("(&(objectClass=gosaMailAccount)(|(mail=$address)".
+ "(gosaMailAlternateAddress=$address)))");
- if ($ldap->count() > 0){
- $attrs= $ldap->fetch ();
- return ($attrs["uid"][0]);
- }
+ if ($ldap->count() > 0){
+ $attrs= $ldap->fetch ();
+ return ($attrs["uid"][0]);
+ }
+
+ /* Add to list of alternates */
+ if (!in_array($address, $this->gosaMailAlternateAddress)){
+ $this->gosaMailAlternateAddress[]= $address;
+ }
- /* Add to list of alternates */
- if (!in_array($address, $this->gosaMailAlternateAddress)){
- $this->gosaMailAlternateAddress[]= $address;
+ sort ($this->gosaMailAlternateAddress);
+ reset ($this->gosaMailAlternateAddress);
+ $this->is_modified= TRUE;
+
+ return ("");
}
- sort ($this->gosaMailAlternateAddress);
- reset ($this->gosaMailAlternateAddress);
- $this->is_modified= TRUE;
- return ("");
-}
+ function delAlternate($addresses)
+ {
+ $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
+ $this->gosaMailAlternateAddress);
+ $this->is_modified= TRUE;
+ }
-function delAlternate($addresses)
-{
- $this->gosaMailAlternateAddress= array_remove_entries ($addresses,
- $this->gosaMailAlternateAddress);
- $this->is_modified= TRUE;
-}
+ function make_name($attrs)
+ {
+ $name= "";
+ if (isset($attrs['sn'][0])){
+ $name= $attrs['sn'][0];
+ }
+ if (isset($attrs['givenName'][0])){
+ if ($name != ""){
+ $name.= ", ".$attrs['givenName'][0];
+ } else {
+ $name.= $attrs['givenName'][0];
+ }
+ }
+ if ($name != ""){
+ $name.= " ";
+ }
+ return ($name);
+ }
-function make_name($attrs)
-{
- $name= "";
- if (isset($attrs['sn'][0])){
- $name= $attrs['sn'][0];
+ function getCopyDialog()
+ {
+ if(!$this->is_account) return("");
+
+ $smarty = get_smarty();
+ $smarty->assign("gosaMailAlternateAddress",$this->gosaMailAlternateAddress);
+ $smarty->assign("gosaMailForwardingAddress",$this->gosaMailForwardingAddress);
+ $smarty->assign("mail",$this->mail);
+ $display= $smarty->fetch (get_template_path('paste_mail.tpl', TRUE));
+ $ret = array();
+ $ret['string'] = $display;
+ $ret['status'] = "";
+ return($ret);
}
- if (isset($attrs['givenName'][0])){
- if ($name != ""){
- $name.= ", ".$attrs['givenName'][0];
- } else {
- $name.= $attrs['givenName'][0];
+
+ function saveCopyDialog()
+ {
+ if(!$this->is_account) return;
+
+ /* Perform ADD / REMOVE ... for mail alternate / mail forwarding addresses
+ */
+ $this->execute();
+ if(isset($_POST['mail'])){
+ $this->mail = $_POST['mail'];
}
}
- if ($name != ""){
- $name.= " ";
+
+
+ function PrepareForCopyPaste($source)
+ {
+ plugin::PrepareForCopyPaste($source);
+
+ /* Reset alternate mail addresses */
+ $this->gosaMailAlternateAddress = array();
}
- return ($name);
-}
+ /* Return plugin informations for acl handling */
+ function plInfo()
+ {
+ return (array(
+ "plShortName" => _("Mail"),
+ "plDescription" => _("Group mail"),
+ "plSelfModify" => FALSE,
+ "plDepends" => array(),
+ "plPriority" => 0,
+ "plSection" => array("administration"),
+ "plCategory" => array("groups"),
+ "plProvidedAcls"=> array(
+ "mail" => _("Mail address"),
+ "gosaMailAlternateAddress" => _("Alternate addresses"),
+ "gosaMailForwardingAddress" => _("Forwarding addresses"),
+ "gosaMailQuota" => _("Quota size"),
+ "gosaMailServer" => _("Mail server"),
+ "acl" => _("Permissions"))
+ ));
+ }
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: