Code

a372071a50c1fc5e7afbc90cd88dd3116bdc0f57
[gosa.git] / trunk / gosa-plugins / goto / admin / systems / services / ldap / class_goLdapServer.inc
1 <?php
3 class goLdapServer extends goService{
5   var $cli_summary      = "This plugin is used within the ServerService Pluign \nand indicates that this server has goLdapServer defined.";
6   var $cli_description  = "Some longer text\nfor help";
7   var $cli_parameters   = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9   /* This plugin only writes its objectClass */
10   var $objectclasses    = array("goLdapServer");
11   var $attributes       = array("goLdapBase");
12   var $StatusFlag       = "goLdapServerStatus";
14   /* This class can't be assigned twice so it conflicts with itsself */
15   var $conflicts        = array("goLdapServer");
17   var $DisplayName      = "";
18   var $dn               = NULL;
19   var $cn                  = "";
20   var $goLdapServerStatus  = "";
21   var $goLdapBase          = ""; 
22   var $oldBase             = ""; 
23   var $view_logged  =FALSE;
25   var $krb_service_prefix = "ldap/";
27   function goLdapServer(&$config,$dn)
28   {
29     goService::goService($config,$dn);
30     $this->DisplayName = _("LDAP service");
32     /* Suggest a default value */
33     if ($this->goLdapBase == ""){
34       if ($this->dn == ""){
35         $srv= _("fill-in-your-servers-dns-name");
36       } else {
37         $srv= preg_replace("/^cn=([^,]+),.*$/", "$1", $this->dn);
38       }
39       $this->goLdapBase= "ldap://$srv:389/".$config->current['BASE'];
40     }
41     $this->oldBase = $this->goLdapBase;
42   }
45   function execute()
46   { 
48     if($this->is_account && !$this->view_logged){
49       $this->view_logged = TRUE;
50       new log("view","server/".get_class($this),$this->dn);
51     }
53     $smarty = get_smarty(); 
54     foreach($this->attributes as $attr){
55       $smarty->assign($attr,$this->$attr);
56     }
57     $tmp = $this->plInfo();
58     foreach($tmp['plProvidedAcls'] as $name => $translated){
59       $smarty->assign($name."ACL",$this->getacl($name));
60     }
61     return($smarty->fetch(get_template_path("goLdapServer.tpl",TRUE,dirname(__FILE__))));
62   }
65   function getListEntry()
66   {
67     $fields  = goService::getListEntry();
68     $fields['Message']    = _("LDAP service");
69     #$fields['AllowEdit']  = true;
70     return($fields);
71   }
75   function check()
76   { 
77     $message = plugin::check();
78     if(empty($this->goLdapBase)){
79       $message[] = msgPool::required(_("Base"));
80     }
81     if(!preg_match("/^ldap[si]?:\/\/[\w-:_]+\/.+$/", $this->goLdapBase)){
82       $err = _('The specified LDAP URI is incorrectly formatted.');
83       $err .= "<br><br><i>"._("Example").":</i> ". "ldap[si]://server/base";
85       $message[] = $err;
86     }
87     return($message);
88   }
91   function save_object()
92   {
93     if(isset($_POST['goLdapServerPosted'])){
94       plugin::save_object();
95     }
96   } 
98   
99   function save()
100   {
101     goService::save();
103     /* Update object relation */
104     if(!empty($this->oldBase) && $this->oldBase != $this->goLdapBase){
105       $new = array();
106       $ldap = $this->config->get_ldap_link();
107       $ldap->cd($this->config->current['BASE']);
108       $ldap->search('(&(objectClass=GOhard)(gotoLdapServer=*'.$this->oldBase.'))',array("cn","gotoLdapServer"));
109       while($attrs = $ldap->fetch()){
110         $ldapServer = array();
111         for($i = 0 ; $i < $attrs['gotoLdapServer']['count'] ; $i ++ ){
112           $ldapServer[] = preg_replace("/".preg_quote($this->oldBase, '/')."/",$this->goLdapBase,$attrs['gotoLdapServer'][$i]);
113         }
114         $new[$attrs['dn']]['gotoLdapServer'] = $ldapServer;
115       }
116       foreach($new as $dn => $data){
117         $ldap->cd($dn);
118         $ldap->modify($data); 
119         if(!$ldap->success()){
120           msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
121         }
122       }
123     }
124   }
127   /* Return plugin informations for acl handling */
128   static function plInfo()
129   {
130     return (array(
131           "plShortName"   => _("Ldap"),
132           "plDescription" => _("Ldap")." ("._("Services").")",
133           "plSelfModify"  => FALSE,
134           "plDepends"     => array(),
135           "plPriority"    => 96,
136           "plSection"     => array("administration"),
137           "plCategory"    => array("server"),
139           "plProvidedAcls"=> array(
140             "goLdapBase" => _("Ldap base"))
141           ));
142   }
144 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
145 ?>