X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fgofax%2Fblocklists%2Fclass_blocklistManagement.inc;h=9b946ee97cce5792d6b571dd05d4f497d11cd463;hb=5d0f48602651da43514bff253b037394b308b25e;hp=3056fb6af96e7f08a90440833e493ba4753d60c4;hpb=e299f0ca47a924516f2afbe4e922f2418b75315c;p=gosa.git diff --git a/plugins/gofax/blocklists/class_blocklistManagement.inc b/plugins/gofax/blocklists/class_blocklistManagement.inc index 3056fb6af..9b946ee97 100644 --- a/plugins/gofax/blocklists/class_blocklistManagement.inc +++ b/plugins/gofax/blocklists/class_blocklistManagement.inc @@ -11,433 +11,571 @@ class blocklist extends plugin var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser"); /* blocklist attributes */ - var $cn= ""; - var $description= ""; - var $type= ""; - var $goFaxBlocklist= array(); - var $base= ""; + var $cn = ""; + var $description = ""; + var $type = ""; + var $base = ""; - /* Headpage attributes */ - var $blocklists= array(); - - /* attribute list for save action */ - var $attributes= array("cn", "description"); - var $objectclasses= array(); + var $goFaxBlocklist = array(); + var $blocklists = array(); + var $attributes = array("cn", "description"); + var $objectclasses = array(); + var $DivListBlocklist = NULL; function blocklist ($config, $ui) { - $this->ui= $ui; - $this->dn= ""; - $this->config= $config; - - /* Get global filter config */ - if (!is_global("blockfilter")){ - $ui= get_userinfo(); - $base= get_base_from_people($ui->dn); - $blockfilter= array("sendlists" => "checked", - "receivelists" => "checked", - "entry" => "*", - "depselect" => $base, - "regex" => "*"); - register_global("blockfilter", $blockfilter); - } + /* Init class */ + $this->ui = $ui; + $this->dn = ""; + $this->config = $config; + $this->DivListBlocklist = new divListBlocklist($this->config,$this); } function execute() { - /* Get global smarty instance */ - $smarty= get_smarty(); - - /* Save data */ - $blockfilter= get_global("blockfilter"); - foreach( array("depselect", "entry", "regex") as $type){ - if (isset($_POST[$type])){ - $blockfilter[$type]= $_POST[$type]; - } + /* Call parent execute */ + plugin::execute(); + + /*************** + Init vars + ***************/ + + /* Get global smarty instance */ + $smarty = get_smarty(); + $s_action = ""; // Contains the action to proceed + $s_entry = ""; // The value for s_action + $base_back = ""; // The Link for Backbutton + + + /*************** + Fetch posts + ***************/ + + /* Test Posts */ + foreach($_POST as $key => $val){ + // Post for delete + if(preg_match("/user_del.*/",$key)){ + $s_action = "del"; + $s_entry = preg_replace("/user_".$s_action."_/i","",$key); + // Post for edit + }elseif(preg_match("/user_edit_.*/",$key)){ + $s_action="edit"; + $s_entry = preg_replace("/user_".$s_action."_/i","",$key); + // Post for new + }elseif(preg_match("/user_new.*/",$key)){ + $s_action="new"; + }elseif(preg_match("/user_tplnew.*/i",$key)){ + $s_action="new_tpl"; + }elseif(preg_match("/user_chgpw.*/i",$key)){ + $s_action="change_pw"; + $s_entry = preg_replace("/user_chgpw_/i","",$key); + } + } + + if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){ + $s_action ="edit"; + $s_entry = $_GET['id']; + } + + $s_entry = preg_replace("/_.$/","",$s_entry); + + + /*************** + Cancel some dialogs + ***************/ + + /* Cancel dialog */ + if (isset($_POST['edit_cancel']) || + isset($_POST['delete_blocklist_cancel']) || + isset($_POST['delete_blocklist_confirm']) || + isset($_POST['delete_lock'])){ + + if(!isset($_POST['delete_blocklist_confirm'])){ + $this->clear_fields(); + } + del_lock ($this->dn); + unset($_SESSION['objectinfo']); + } + + + /*************** + Cancel some dialogs + ***************/ + + /* Create new blocklist? */ + if ($s_action=="new"){ + $this->clear_fields(); + $this->dn= "new"; + plugin::plugin ($this->config, $this->dn); + } + + + /*************** + Edit blocklist + ***************/ + + /* Edit selected blocklist? */ + if (($s_action=="edit") && (empty($this->dn))){ + $this->clear_fields(); + $this->dn=$this->blocklists[$s_entry]['dn']; + if (($user= get_lock($this->dn)) != ""){ + $_SESSION['dn']= $this->dn; + //$this->dn =""; + return(gen_locked_message($user, $this->dn)); + } else { +# Lock this dn for editing + add_lock ($this->dn, $this->ui->dn); + + plugin::plugin ($this->config, $this->dn); + + /* Load missing lists */ + if (in_array("goFaxSBlock",$this->attrs['objectClass'])){ + if(isset($this->attrs["goFaxSBlocklist"])){ + for ($i= 0; $i<$this->attrs["goFaxSBlocklist"]["count"]; $i++){ + $this->goFaxBlocklist[]= $this->attrs["goFaxSBlocklist"][$i]; + } + } + $this->type= 0; + } elseif (in_array("goFaxRBlock",$this->attrs['objectClass'])){ + if(isset($this->attrs["goFaxRBlocklist"])){ + for ($i= 0; $i<$this->attrs["goFaxRBlocklist"]["count"]; $i++){ + $this->goFaxBlocklist[]= $this->attrs["goFaxRBlocklist"][$i]; + } + } + $this->type= 1; + } + $_SESSION['objectinfo']= trim($this->dn); + } + } + + + /*************** + Remove blocklist + ***************/ + + /* Delete blocklist requested */ + if ($s_action=="del"){ + $this->dn=$this->blocklists[$s_entry]['dn']; + /* Check locking */ + if (($user= get_lock($this->dn)) != ""){ + $_SESSION['dn']= $this->dn; + return(gen_locked_message($user, $this->dn)); + } else { +# Lock this dn for editing + add_lock ($this->dn, $this->ui->dn); + + $smarty->assign("info", sprintf(_("You're about to delete the blocklist '%s'."), $this->dn)); + return($smarty->fetch(get_template_path('remove.tpl', TRUE))); + } + } + + + /*************** + Remove blocklist confirmed + ***************/ + + /* Finally delete blocklist */ + if (isset($_POST['delete_blocklist_confirm'])){ + if (chkacl($this->acl, "delete") == ""){ + $this->remove_from_parent(); + gosa_log ("Blocklist object'".$this->dn."' has been removed"); + $this->reload (); + } else { + print_red (_("You have no permission to remove this blocklist.")); + } + } + + + /*************** + Add numer to blocklist + ***************/ + + + /* Handle interactions: add */ + if (isset($_POST['add_number']) && $_POST['number'] != ""){ + if (is_phone_nr($_POST['number'])){ + $this->addNumber ($_POST['number']); + } else { + print_red (_("Please specify a valid phone number.")); + } + } + + + /*************** + Delete number from list + ***************/ + + /* Handle interactions: delete */ + if (isset($_POST['delete_number']) && count($_POST['numbers']) > 0){ + $this->delNumber ($_POST['numbers']); + } + + + /*************** + Edit finished + ***************/ + + /* What about finish? */ + if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (!empty($this->dn))){ + $message= $this->check(); + $this->remove_lock(); + + /* No errors, save object */ + if (count ($message) == 0){ + + /* Perpare 'dn' in case of new entries */ + if ($this->dn == "new"){ + $this->dn= "cn=$this->cn,ou=gofax,ou=systems,".$this->base; + } + + $this->save (); + gosa_log ("Blocklist object'".$this->dn."' has been saved"); + + if (!isset($_POST['edit_apply'])){ + $this->dn= ""; + del_lock ($this->ui->dn); + unset($_SESSION['objectinfo']); } - if (isset($_POST['depselect'])){ - foreach( array("sendlists", "receivelists") as $type){ - - if (isset($_POST[$type])) { - $blockfilter[$type]= "checked"; - } else { - $blockfilter[$type]= ""; - } - } + } else { + /* Errors found, show message */ + show_errors ($message); + } + } + + + /*************** + Object currently in edit + ***************/ + + if($this->dn){ + + /* Base select dialog */ + $once = true; + foreach($_POST as $name => $value){ + if(preg_match("/^chooseBase/",$name) && $once){ + $once = false; + $this->dialog = new baseSelectDialog($this->config,$this); + $this->dialog->setCurrentBase($this->base); } - if (isset($_GET['search'])){ - $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*"; - if ($s == "**"){ - $s= "*"; - } - $blockfilter['regex']= $s; + } + + /* Dialog handling */ + if(is_object($this->dialog)){ + /* Must be called before save_object */ + $this->dialog->save_object(); + + if($this->dialog->isClosed()){ + $this->dialog = false; + }elseif($this->dialog->isSelected()){ + $this->base = $this->dialog->isSelected(); + $this->dialog= false; + }else{ + return($this->dialog->execute()); } - register_global("blockfilter", $blockfilter); - - /* Create new blocklist? */ - if (isset($_POST['new_blocklist'])){ - $this->clear_fields(); - $this->acl= "#all#"; - $this->dn= "new"; - plugin::plugin ($this->config, $this->dn); - } - - /* Edit selected blocklist? */ - if ((isset($_POST['select_blocklist']) || (isset($_POST['edit_helper']) && $_POST['edit_helper'] == "1")) && isset($_POST['blocklist']) != ""){ - $this->clear_fields(); - $this->dn= trim($_POST['blocklist']); - $this->acl= get_permissions ($this->dn, $this->ui->subtreeACL); - $this->acl= get_module_permission($this->acl, "blocklists", $this->dn); - plugin::plugin ($this->config, $this->dn); - - /* Load missing lists */ - if (isset($this->attrs["goFaxSBlocklist"])){ - for ($i= 0; $i<$this->attrs["goFaxSBlocklist"]["count"]; $i++){ - $this->goFaxBlocklist[]= $this->attrs["goFaxSBlocklist"][$i]; - } - $this->type= 0; - } elseif (isset($this->attrs["goFaxRBlocklist"])){ - for ($i= 0; $i<$this->attrs["goFaxRBlocklist"]["count"]; $i++){ - $this->goFaxBlocklist[]= $this->attrs["goFaxRBlocklist"][$i]; - } - $this->type= 1; - } - $_SESSION['objectinfo']= trim($this->dn); - } - - /* Delete blocklist requested */ - if (isset($_POST['delete_blocklist']) && isset($_POST['blocklist'])){ - $this->dn= trim($_POST['blocklist']); - - /* Check locking */ - if (($user= get_lock($this->dn)) != ""){ - $_SESSION['dn']= $this->dn; - return(gen_locked_message($user, $this->dn)); - } else { - # Lock this dn for editing - add_lock ($this->dn, $this->ui->dn); - - $smarty->assign("info", sprintf(_("You're about to delete the blocklist '%s'."), $this->dn)); - return($smarty->fetch(get_template_path('remove.tpl', TRUE))); - } - } - - /* Finally delete blocklist */ - if (isset($_POST['delete_blocklist_confirm'])){ - $acl= get_permissions ($this->dn, $this->ui->subtreeACL); - $acl= get_module_permission($acl, "blocklists", $this->dn); - if (chkacl($acl, "all") == ""){ - $this->remove_from_parent(); - gosa_log ("Blocklist object'".$this->dn."' has been removed"); - $this->reload (); - } else { - print_red (_("You have no permission to remove this blocklist.")); - } - } - - /* Cancel dialog */ - if (isset($_POST['edit_cancel']) || isset($_POST['delete_blocklist_cancel']) || - isset($_POST['delete_blocklist_confirm']) || isset($_POST['delete_lock'])){ - - del_lock ($this->dn); - $this->clear_fields(); - unset($_SESSION['objectinfo']); - } - - /* Handle interactions: add */ - if (isset($_POST['add_number']) && $_POST['number'] != ""){ - if (is_phone_nr($_POST['number'])){ - $this->addNumber ($_POST['number']); - } else { - print_red (_("Please specify a valid phone number.")); - } - } - - /* Handle interactions: delete */ - if (isset($_POST['delete_number']) && count($_POST['numbers']) > 0){ - $this->delNumber ($_POST['numbers']); - } - - /* What about finish? */ - if (isset($_POST['edit_finish'])){ - $message= $this->check(); - - /* No errors, save object */ - if (count ($message) == 0){ - - /* Perpare 'dn' in case of new entries */ - if ($this->dn == "new"){ - $this->dn= "cn=$this->cn,ou=gofax,ou=systems,".$this->base; - } - - $this->save (); - gosa_log ("Blocklist object'".$this->dn."' has been saved"); - $this->acl= "#none#"; - $this->dn= ""; - del_lock ($this->ui->dn); - unset($_SESSION['objectinfo']); - } else { - /* Errors found, show message */ - show_errors ($message); - } - } - - /* Headpage or normal plugin screen? */ - if ($this->dn == ""){ - /* Check sorting variable */ - $this->reload(); - - /* Check for exeeded sizelimit */ - if (($message= check_sizelimit()) != ""){ - return($message); - } - - /* Show main page */ - $smarty->assign("blocklists", $this->blocklists); - $smarty->assign("search_image", get_template_path('images/search.png')); - $smarty->assign("tree_image", get_template_path('images/tree.png')); - $smarty->assign("infoimage", get_template_path('images/info.png')); - $smarty->assign("launchimage", get_template_path('images/launch.png')); - $smarty->assign("apply", apply_filter()); - foreach( array("depselect", "entry", "regex", "sendlists", "receivelists") as $type){ - $smarty->assign("$type", $blockfilter[$type]); - } - $smarty->assign("deplist", $this->config->idepartments); - $smarty->assign("alphabet", generate_alphabet()); - $smarty->assign("hint", print_sizelimit_warning()); - - return($smarty->fetch(get_template_path('headpage.tpl', TRUE))); - } - - /* Set base */ - if ($this->base == ""){ - if ($this->dn == "new"){ - $ui= get_userinfo(); - $this->base= dn2base($ui->dn); - } else { - $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn); - } - } - - /* Fill templating stuff */ - $smarty->assign("bases", $this->config->idepartments); - $smarty->assign("base_select", $this->base); - $smarty->assign("types", array(0 => _("send"), 1 => _("receive"))); - if ($this->dn == "new" || preg_match ("/,ou=incoming,/", $this->dn)){ - $smarty->assign("selectmode", ""); - $smarty->assign("mode", ""); + } + + /* Set base */ + if ($this->base == ""){ + if ($this->dn == "new"){ + $ui= get_userinfo(); + $this->base= dn2base($ui->dn); } else { - $smarty->assign("selectmode", "disabled"); - $smarty->assign("mode", "readonly"); + $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn); } - foreach(array("cn", "description", "type", "goFaxBlocklist") as $val){ - $smarty->assign("$val", $this->$val); - $smarty->assign("$val"."ACL", chkacl($this->acl, "$val")); - } + } + + /* Fill templating stuff */ + $smarty->assign("bases", $this->config->idepartments); + $smarty->assign("base_select", $this->base); + $smarty->assign("types", array(0 => _("send"), 1 => _("receive"))); + if ($this->dn == "new" || preg_match ("/,ou=incoming,/", $this->dn)){ + $smarty->assign("selectmode", ""); + $smarty->assign("mode", ""); + $smarty->assign("apply", "0"); + } else { + $smarty->assign("selectmode", "disabled"); + $smarty->assign("mode", "readonly"); + $smarty->assign("apply", "1"); + } + foreach(array("cn", "description", "type", "goFaxBlocklist") as $val){ + $smarty->assign("$val", $this->$val); + $smarty->assign("$val"."ACL", chkacl($this->acl, "$val")); + } + + /* Lock blocklist type for non new entries */ + if ($this->dn != "new"){ + $smarty->assign('typeACL', "disabled"); + } + + /* Show main page */ + return($smarty->fetch (get_template_path('generic.tpl', TRUE))); + + }else{ + + /*************** + Divlist dialog + ***************/ + + /* Check if there is a snapshot dialog open */ + $base = $this->DivListBlocklist->selectedBase; + if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){ + return($str); + } + + /* Display dialog with system list */ + $this->DivListBlocklist->parent = $this; + $this->DivListBlocklist->execute(); + + /* Add departments if subsearch is disabled */ + if(!$this->DivListBlocklist->SubSearch){ + $this->DivListBlocklist->AddDepartments($this->DivListBlocklist->selectedBase); + } + $this->reload(); + $this->DivListBlocklist->setEntries($this->blocklists); + return($this->DivListBlocklist->Draw()); + } + } + - /* Show main page */ - return($smarty->fetch (get_template_path('generic.tpl', TRUE))); + /* Return departments, that will be included within snapshot detection */ + function get_used_snapshot_bases() + { + return(array("ou=gofax,ou=systems,". $this->DivListBlocklist->selectedBase)); } + + /* Clear garbage from edited lists */ function clear_fields() { - $this->dn= ""; - $this->description= ""; - $this->cn= ""; - $this->base= ""; - $this->goFaxBlocklist= array(); - $this->acl= "#none#"; + $this->dn= ""; + $this->description= ""; + $this->cn= ""; + $this->base= $_SESSION['CurrentMainBase']; + $this->goFaxBlocklist= array(); } + + /* Reload the list of known blocklists */ function reload() { - /* Get config */ - $blockfilter= get_global('blockfilter'); - - /* Set base for all searches */ - $base= $blockfilter['depselect']; - $filter= ""; - - /* Regex filter? */ - if ($blockfilter['regex'] != ""){ - $regex= $blockfilter['regex']; - } else { - $regex= "*"; - } - - /* Entry filter? */ - /* Get list of blocklists to be shown */ - if ($blockfilter['sendlists'] == "checked"){ - $filter.= "(objectClass=goFaxSBlock)"; - } - if ($blockfilter['receivelists'] == "checked"){ - $filter.= "(objectClass=goFaxRBlock)"; - } - if ($filter != ""){ - $filter= "(|$filter)"; - } - - if ($blockfilter['entry'] != "" && $blockfilter['entry'] != "*"){ - $filter.= "(|(goFaxSBlocklist=".$blockfilter['entry'].")(goFaxRBlocklist=".$blockfilter['entry']."))"; - } - - /* Generate blocklists */ - $res= get_list($this->ui->subtreeACL, "(&(cn=$regex)$filter)", TRUE, $base, array("cn", "description")); - - $this->blocklists= array(); - foreach ($res as $value){ - - /* Unwanted? */ - $this->blocklists[$value["dn"]]= $value["cn"][0]; - if (isset($value["description"][0])){ - $this->blocklists[$value["dn"]]= $value["cn"][0]." (". - $value["description"][0].")"; - } - } - natcasesort ($this->blocklists); - reset ($this->blocklists); + /* Init some vars */ + $filter = $filter2 = ""; + $base = $this->DivListBlocklist->selectedBase; + $Regex = $this->DivListBlocklist->Regex; + $SubSearch = $this->DivListBlocklist->SubSearch; + $ShowSendBocklists = $this->DivListBlocklist->ShowSendBocklists; + $ShowReceiveBlocklists = $this->DivListBlocklist->ShowReceiveBlocklists; + $Flags = GL_SIZELIMIT; + $res = $res2 = array(); + + /* Append subsearch to Flags */ + if($SubSearch){ + $Flags |= GL_SUBSEARCH; + }else{ + $base = "ou=gofax,ou=systems,".$base; + } + + /* Create filter */ + if ($ShowSendBocklists){ + $filter = "(&(objectClass=goFaxSBlock)(|(cn=".$Regex.")(goFaxSBlocklist=".$Regex.")))"; + $res= get_list($filter, "gofax", $base,array("*"), $Flags); + } + if ($ShowReceiveBlocklists){ + $filter2= "(&(objectClass=goFaxRBlock)(|(cn=".$Regex.")(goFaxRBlocklist=".$Regex.")))"; + $res2= get_list($filter2, "gofax", $base,array("*"), $Flags); + } + + $this->blocklists = array_merge($res,$res2); + + /* appen && sort */ + $tmp=array(); + foreach($this->blocklists as $tkey => $val ){ + $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val; + } + ksort($tmp); + $this->blocklists=array(); + foreach($tmp as $val){ + $this->blocklists[]=$val; + } + reset ($this->blocklists); } + function remove_from_parent() { - $ldap= $this->config->get_ldap_link(); - $ldap->rmDir($this->dn); - $this->handle_post_events("remove"); + $ldap= $this->config->get_ldap_link(); + $ldap->rmDir($this->dn); + show_ldap_error($ldap->get_error(), sprintf(_("Removing of blocklist with dn '%s' failed."),$this->dn)); + $this->clear_fields(); + $this->handle_post_events("remove"); } /* Save data to object */ function save_object() { - plugin::save_object(); - - /* Save type, needed to detect objectClass */ - if (isset($_POST['type']) && chkacl($this->acl, "cn") == ""){ - $this->type= $_POST['type']; - } - - /* Save base, since this is no LDAP attribute */ - if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){ - $this->base= $_POST['base']; - } + $this->DivListBlocklist->save_object(); + plugin::save_object(); + + if(isset($_POST['base'])){ + $this->base = $_POST['base']; + } + foreach($this->attributes as $attr){ + if(isset($_POST[$attr])){ + $this->$attr = $_POST[$attr]; + } + } + if(isset($_POST['type'])){ + $this->type = $_POST['type']; + } } /* Check values */ function check() { - $message= array(); - - /* Permissions for that base? */ - if ($this->base != ""){ - $new_dn= "cn=".$this->cn.",ou=gofax,ou=systems,".$this->base; - } else { - $new_dn= $this->dn; - } - - $ui= get_userinfo(); - $acl= get_permissions ($new_dn, $ui->subtreeACL); - $acl= get_module_permission($acl, "blocklist", $new_dn); - if (chkacl($acl, "create") != ""){ - $message[]= _("You have no permissions to create a blocklist on this 'Base'."); - } - - - /* check syntax: must cn */ - if ($this->cn == ""){ - $message[]= _("Required field 'Name' is not set."); - } else { - if (!is_uid($this->cn)){ - $message[]= _("Required field 'Name' contains invalid characters"); - } - if ($this->dn == 'new'){ - $ldap= $this->config->get_ldap_link(); - $ldap->cd ("ou=gofax,ou=systems,".$this->config->current["BASE"]); - $ldap->search ("(&(|(objectClass=goFaxSBlock)(objectClass=goFaxRBlock))". - "(cn=".$this->cn."))", array("cn")); - if ($ldap->count() != 0){ - $message[]= _("Specified name is already used."); - } - } - } - - /* Is user allowed to create in 'base'? */ - if (chkacl($this->acl, "create") != ""){ - $message[]= _("No permission to create a blocklist on this base."); - } - - return $message; + /* Call common method to give check the hook */ + $message= plugin::check(); + + /* Permissions for that base? */ + if ($this->base != ""){ + $new_dn= "cn=".$this->cn.",ou=gofax,ou=systems,".$this->base; + } else { + $new_dn= $this->dn; + } + + if (chkacl($this->acl, "create") != ""){ + $message[]= _("You have no permissions to create a blocklist on this 'Base'."); + } + + + /* check syntax: must cn */ + if ($this->cn == ""){ + $message[]= _("Required field 'Name' is not set."); + } else { + if (!is_uid($this->cn)){ + $message[]= _("Required field 'Name' contains invalid characters"); + } + if ($this->dn == 'new'){ + $ldap= $this->config->get_ldap_link(); + $ldap->cd ("ou=gofax,ou=systems,".$this->config->current["BASE"]); + $ldap->search ("(&(|(objectClass=goFaxSBlock)(objectClass=goFaxRBlock))(cn=".$this->cn."))", array("cn")); + if ($ldap->count() != 0){ + $message[]= _("Specified name is already used."); + } + } + } + + /* Is user allowed to create in 'base'? */ + if (chkacl($this->acl, "create") != ""){ + $message[]= _("No permission to create a blocklist on this base."); + } + + return $message; } /* Save to LDAP */ function save() { - plugin::save(); - - /* Type selection */ - if ($this->type == 0){ - $type= "goFaxSBlock"; - } else { - $type= "goFaxRBlock"; - } - - /* Add list */ - $this->attrs['objectClass']= $type; - if (count($this->goFaxBlocklist)){ - $this->attrs["$type"."list"]= $this->goFaxBlocklist; - } - - /* Write back to ldap */ - $ldap= $this->config->get_ldap_link(); - $ldap->cd($ldap->getParentDir($this->dn)); - $ldap->search("cn=$this->cn"); - $a= $ldap->fetch(); - if (count($a)){ - if (!isset($this->attrs["$type"."list"])){ - $this->attrs["$type"."list"]= array(); - } - $ldap->cd($this->dn); - $ldap->modify($this->attrs); - $this->handle_post_events("modify"); - } else { - $ldap->cd($this->config->current['BASE']); - $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn)); - $ldap->cd($this->dn); - $ldap->add($this->attrs); - $this->handle_post_events("add"); - } - show_ldap_error($ldap->get_error()); + plugin::save(); + + + /* Type selection */ + if ($this->type == 0){ + $type= "goFaxSBlock"; + } else { + $type= "goFaxRBlock"; + } + + /* Add list */ + $this->attrs['objectClass']= $type; + if (count($this->goFaxBlocklist)){ + $this->attrs["$type"."list"]= $this->goFaxBlocklist; + } + + /* Write back to ldap */ + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->base); + $ldap->search("cn=$this->cn",array("cn")); + $ldap->cat($this->dn, array('dn')); + $a= $ldap->fetch(); + + if (count($a)){ + if (!isset($this->attrs["$type"."list"])){ + $this->attrs["$type"."list"]= array(); + } + $ldap->cd($this->dn); + $this->cleanup(); + $ldap->modify($this->attrs); + $this->handle_post_events("modify"); + } else { + $ldap->cd($this->config->current['BASE']); + $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn)); + $ldap->cd($this->dn); + $ldap->add($this->attrs); + $this->handle_post_events("add"); + } + show_ldap_error($ldap->get_error(), sprintf(_("Saving of blocklist with dn '%s' failed."),$this->dn)); } + /* Add number */ function addNumber($number) { - if (!in_array($number, $this->goFaxBlocklist)){ - $this->goFaxBlocklist[]= $number; - sort($this->goFaxBlocklist); - } + if (!in_array($number, $this->goFaxBlocklist)){ + $this->goFaxBlocklist[]= $number; + sort($this->goFaxBlocklist); + } } + + /* Remove number from list */ function delNumber($numbers) { - $tmp= array(); - foreach ($this->goFaxBlocklist as $val){ - if (!in_array($val, $numbers)){ - $tmp[]= $val; - } - } - $this->goFaxBlocklist= $tmp; + $tmp= array(); + foreach ($this->goFaxBlocklist as $val){ + if (!in_array($val, $numbers)){ + $tmp[]= $val; + } + } + $this->goFaxBlocklist= $tmp; } + + /* Delete lock */ function remove_lock() { - if (isset($this->dn)){ - del_lock ($this->dn); - } + if (isset($this->dn)){ + del_lock ($this->dn); + } } -} + /* Return plugin informations for acl handling */ + function plInfo() + { + return (array( + "plShortName" => _("Fax"), + "plDescription" => _("Fax Blocklists"), + "plSelfModify" => TRUE, + "plDepends" => array(), + + "plPriority" => 0, + "plSection" => array("administration" => _("FAX Blocklists")), + "plCategory" => array("gofax" => array("description" => _("Fax"), + "objectClass" => array("goFaxRBlock","goFaxSBlock"))), + + + + "plProvidedAcls" => array( + "cn" => _("Name"), + "description" => _("Description"), + "base" => _("Base"), + "type" => _("Blocklist type")) + )); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?>