Code

Fixed Translation Strings.
[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();
60     /* Check if this is a new entry ... add/modify */
61     $ldap = $this->config->get_ldap_link();
62     $ldap->cat($this->dn,array("objectClass"));
63     if($ldap->count()){
64       $ldap->cd($this->dn);
65       $ldap->modify($this->attrs);
66     }else{
67       $ldap->cd($this->dn);
68       $ldap->add($this->attrs);
69     }
70     show_ldap_error($ldap->get_error());
71     $this->handle_post_events("remove");
72   }
75   function save()
76   {
77     plugin::save();
78     /* Check if this is a new entry ... add/modify */
79     $ldap = $this->config->get_ldap_link();
80     $ldap->cat($this->dn,array("objectClass"));
81     if($ldap->count()){
82       $ldap->cd($this->dn);
83       $ldap->modify($this->attrs);
84     }else{
85       $ldap->cd($this->dn);
86       $ldap->add($this->attrs);
87     }
88     show_ldap_error($ldap->get_error());
89     if($this->initially_was_account){
90       $this->handle_post_events("modify");
91     }else{
92       $this->handle_post_events("add");
93     }
95   }
98   /* Directly save new status flag */
99   function setStatus($value)
100   {
101     if($value == "none") return;
102     if(!$this->initially_was_account) return;
103     $ldap = $this->config->get_ldap_link();
104     $ldap->cd($this->dn);
105     $ldap->cat($this->dn,array("objectClass"));
106     if($ldap->count()){
108       $tmp = $ldap->fetch();
109       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
110         $attrs['objectClass'][] = $tmp['objectClass'][$i];
111       }
112       $flag = $this->StatusFlag;
113       $attrs[$flag] = $value;
114       $this->$flag = $value;
115       $ldap->modify($attrs);
116       show_ldap_error($ldap->get_error());
117       $this->action_hook();
118     }
119   }
122   function check()
123   { 
124     $message = plugin::check();
125     if(empty($this->goLdapBase)){
126       $message[] = _("The given base is empty or contains invalid characters.");
127     }
128     return($message);
129   }
132   function save_object()
133   {
134     if(isset($_POST['goLdapServerPosted'])){
135       plugin::save_object();
136     }
137   } 
139   function action_hook($add_attrs= array())
140   {
141     /* Find postcreate entries for this class */
142     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
143     if ($command == "" && isset($this->config->data['TABS'])){
144       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
145     }
146     if ($command != ""){
147       /* Walk through attribute list */
148       foreach ($this->attributes as $attr){
149         if (!is_array($this->$attr)){
150           $command= preg_replace("/%$attr/", $this->$attr, $command);
151         }
152       }
153       $command= preg_replace("/%dn/", $this->dn, $command);
154       /* Additional attributes */
155       foreach ($add_attrs as $name => $value){
156         $command= preg_replace("/%$name/", $value, $command);
157       }
159       /* If there are still some %.. in our command, try to fill these with some other class vars */
160       if(preg_match("/%/",$command)){
161         $attrs = get_object_vars($this);
162         foreach($attrs as $name => $value){
163           if(!is_string($value)) continue;
164           $command= preg_replace("/%$name/", $value, $command);
165         }
166       }
168       if (check_command($command)){
169         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
170             $command, "Execute");
172         exec($command);
173       } else {
174         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
175         print_red ($message);
176       }
177     }
178   }
180   /* Get updates for status flag */
181   function updateStatusState()
182   {
183     if(empty($this->StatusFlag)) return;
185     $attrs = array();
186     $flag = $this->StatusFlag;
187     $ldap = $this->config->get_ldap_link();
188     $ldap->cd($this->cn);
189     $ldap->cat($this->dn,array($flag));
190     if($ldap->count()){
191       $attrs = $ldap->fetch();
192     }
193     if(isset($attrs[$flag][0])){
194       $this->$flag = $attrs[$flag][0];
195     }
196   }
198 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
199 ?>