Code

165659b461ef19b0cbafccafe318685bb45970c5
[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]?:\/\/[^\/]+\/.+$/", $this->goLdapBase)){
82       $message[] = msgPool::invalid(_("Base"),"","","ldap[si]://base");
83     }
84     return($message);
85   }
88   function save_object()
89   {
90     if(isset($_POST['goLdapServerPosted'])){
91       plugin::save_object();
92     }
93   } 
95   
96   function save()
97   {
98     goService::save();
100     /* Update object relation */
101     if(!empty($this->oldBase) && $this->oldBase != $this->goLdapBase){
102       $new = array();
103       $ldap = $this->config->get_ldap_link();
104       $ldap->cd($this->config->current['BASE']);
105       $ldap->search('(&(objectClass=GOhard)(gotoLdapServer=*'.$this->oldBase.'))',array("cn","gotoLdapServer"));
106       while($attrs = $ldap->fetch()){
107         $ldapServer = array();
108         for($i = 0 ; $i < $attrs['gotoLdapServer']['count'] ; $i ++ ){
109           $ldapServer[] = preg_replace("/".preg_quote($this->oldBase, '/')."/",$this->goLdapBase,$attrs['gotoLdapServer'][$i]);
110         }
111         $new[$attrs['dn']]['gotoLdapServer'] = $ldapServer;
112       }
113       foreach($new as $dn => $data){
114         $ldap->cd($dn);
115         $ldap->modify($data); 
116         if(!$ldap->success()){
117           msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
118         }
119       }
120     }
121   }
124   /* Return plugin informations for acl handling */
125   static function plInfo()
126   {
127     return (array(
128           "plShortName"   => _("Ldap"),
129           "plDescription" => _("Ldap")." ("._("Services").")",
130           "plSelfModify"  => FALSE,
131           "plDepends"     => array(),
132           "plPriority"    => 96,
133           "plSection"     => array("administration"),
134           "plCategory"    => array("server"),
136           "plProvidedAcls"=> array(
137             "goLdapBase" => _("Ldap base"))
138           ));
139   }
141 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
142 ?>