Code

Added acls for printer glpi
[gosa.git] / plugins / admin / systems / class_goLdapServer.inc
1 <?php
3 class goLdapServer extends plugin{
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 $acl;
20   var $cn                  = "";
21   var $goLdapServerStatus  = "";
22   var $goLdapBase          = ""; 
24   function goLdapServer($config,$dn)
25   {
26     plugin::plugin($config,$dn);
27     $this->DisplayName = _("LDAP service");
28   }
31   function execute()
32   { 
33     $smarty = get_smarty(); 
34     foreach($this->attributes as $attr){
35       $smarty->assign($attr,$this->$attr);
36       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
37     }
38     return($smarty->fetch(get_template_path("goLdapServer.tpl",TRUE,dirname(__FILE__))));
39   }
42   function getListEntry()
43   {
44     $this->updateStatusState();
45     $flag = $this->StatusFlag;
46     $fields['Status']     = $this->$flag;
47     $fields['Message']    = _("LDAP Service");
48     $fields['AllowStart'] = true;
49     $fields['AllowStop']  = true;
50     $fields['AllowRestart'] = true;
51     $fields['AllowRemove']= true;
52     $fields['AllowEdit']  = true;
53     return($fields);
54   }
57   function remove_from_parent()
58   {
59     plugin::remove_from_parent();
61     /* Remove status flag, it is not a memeber of 
62         this->attributes, so ensure that it is deleted too */
63     if(!empty($this->StatusFlag)){
64       $this->attrs[$this->StatusFlag] = array();
65     }
67     /* Check if this is a new entry ... add/modify */
68     $ldap = $this->config->get_ldap_link();
69     $ldap->cat($this->dn,array("objectClass"));
70     if($ldap->count()){
71       $ldap->cd($this->dn);
72       $ldap->modify($this->attrs);
73     }else{
74       $ldap->cd($this->dn);
75       $ldap->add($this->attrs);
76     }
77     show_ldap_error($ldap->get_error(), sprintf(_("Removing server services/ldap with dn '%s' failed."),$this->dn));
78     $this->handle_post_events("remove");
79   }
82   function save()
83   {
84     plugin::save();
85     /* Check if this is a new entry ... add/modify */
86     $ldap = $this->config->get_ldap_link();
87     $ldap->cat($this->dn,array("objectClass"));
88     if($ldap->count()){
89       $ldap->cd($this->dn);
90       $ldap->modify($this->attrs);
91     }else{
92       $ldap->cd($this->dn);
93       $ldap->add($this->attrs);
94     }
95     show_ldap_error($ldap->get_error(), sprintf(_("Saving server services/ldap with dn '%s' failed."),$this->dn));
96     if($this->initially_was_account){
97       $this->handle_post_events("modify");
98     }else{
99       $this->handle_post_events("add");
100     }
102   }
105   /* Directly save new status flag */
106   function setStatus($value)
107   {
108     if($value == "none") return;
109     if(!$this->initially_was_account) return;
110     $ldap = $this->config->get_ldap_link();
111     $ldap->cd($this->dn);
112     $ldap->cat($this->dn,array("objectClass"));
113     if($ldap->count()){
115       $tmp = $ldap->fetch();
116       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
117         $attrs['objectClass'][] = $tmp['objectClass'][$i];
118       }
119       $flag = $this->StatusFlag;
120       $attrs[$flag] = $value;
121       $this->$flag = $value;
122       $ldap->modify($attrs);
123       show_ldap_error($ldap->get_error(), sprintf(_("Set status flag for server services/ldap with dn '%s' failed."),$this->dn));
124       $this->action_hook();
125     }
126   }
129   function check()
130   { 
131     $message = plugin::check();
132     if(empty($this->goLdapBase)){
133       $message[] = _("The given base is empty or contains invalid characters.");
134     }
135     return($message);
136   }
139   function save_object()
140   {
141     if(isset($_POST['goLdapServerPosted'])){
142       plugin::save_object();
143     }
144   } 
146   function action_hook($add_attrs= array())
147   {
148     /* Find postcreate entries for this class */
149     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
150     if ($command == "" && isset($this->config->data['TABS'])){
151       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
152     }
153     if ($command != ""){
154       /* Walk through attribute list */
155       foreach ($this->attributes as $attr){
156         if (!is_array($this->$attr)){
157           $command= preg_replace("/%$attr/", $this->$attr, $command);
158         }
159       }
160       $command= preg_replace("/%dn/", $this->dn, $command);
161       /* Additional attributes */
162       foreach ($add_attrs as $name => $value){
163         $command= preg_replace("/%$name/", $value, $command);
164       }
166       /* If there are still some %.. in our command, try to fill these with some other class vars */
167       if(preg_match("/%/",$command)){
168         $attrs = get_object_vars($this);
169         foreach($attrs as $name => $value){
170           if(!is_string($value)) continue;
171           $command= preg_replace("/%$name/", $value, $command);
172         }
173       }
175       if (check_command($command)){
176         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
177             $command, "Execute");
179         exec($command);
180       } else {
181         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
182         print_red ($message);
183       }
184     }
185   }
187   /* Get updates for status flag */
188   function updateStatusState()
189   {
190     if(empty($this->StatusFlag)) return;
192     $attrs = array();
193     $flag = $this->StatusFlag;
194     $ldap = $this->config->get_ldap_link();
195     $ldap->cd($this->cn);
196     $ldap->cat($this->dn,array($flag));
197     if($ldap->count()){
198       $attrs = $ldap->fetch();
199     }
200     if(isset($attrs[$flag][0])){
201       $this->$flag = $attrs[$flag][0];
202     }
203   }
206   /* Return plugin informations for acl handling */
207   function plInfo()
208   {
209     return (array(
210           "plShortName"   => _("Ldap"),
211           "plDescription" => _("Ldap service"),
212           "plSelfModify"  => FALSE,
213           "plDepends"     => array(),
214           "plPriority"    => 0,
215           "plSection"     => array("administration"),
216           "plCategory"    => array("server"),
218           "plProvidedAcls"=> array(
219             "goLdapBase" => _("Ldap base"))
220           ));
221   }
223 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
224 ?>